月の差分

何月前か後ろかを整数で返す

//  js月の比較
const date1 = new Date(2021, 1, 1)
const date2 = new Date(2021, 12, 11)

let months
months = (date2.getFullYear() - date1.getFullYear()) * 12
months -= date1.getMonth() + 1
months += date2.getMonth() + 1

日の差分

単純に日数の差分を返す

//  js日差分
const date1 = new Date(2021, 1, 1)
const date2 = new Date(2021, 12, 11)
const termDay = (date2 - date1) / 86400000
console.log(termDay)