The input parameter is in the format of new Date('2023-01-13 10:14:30')
export function getDiffDay(date_1, date_2) {
if (!date_1 || !date_2) return 0
const myDate_1 = Date.parse(date_1)
const myDate_2 = Date.parse(date_2)
const diffDate = Math.abs(myDate_1 - myDate_2)
const totalDays = Math.floor(diffDate / (1000 * 3600 * 24))
return totalDays
}
The Date.parse() function is used to analyze a string containing a date and return the number of milliseconds between the date and midnight on January 1, 1970. This function belongs to the Date object and is supported by all major browsers.