const subtractDate = function(date1, date2){
const date1Inms = date1.getTime()
const date2Inms = date2.getTime()
const subtract = new Date(date2Inms - date1Inms)
return subtract
}
const addDate = function(date1, days){
const date1Inms = date1.getTime()
const dayInms = days*86400000
const add = new Date(dayInms + date1Inms)
return new Date(add)
}
my addDate function works correctly but I am getting error "date1.getTime is not a function" for subtractDate . I dont why ? I used getTime() in both but it throws error only in subtract function
use this, should works.
const subtractDate = (date1, date2) => new Date(date2.getTime() - date.getTime());