I am trying to get the difference between two dates using date fns, but the result is NaN.
import { format, differenceInCalendarDays, parseISO, formatDistance } from "date-fns";
import { ru } from 'date-fns/locale';
export function getCurrentDate() {
const date = new Date();
const pattern = `PPp`;
return format(date, pattern, {locale: ru});
}
export function getDifferenceDate(startDate, endDate) {
const start = startDate;
const end = endDate;
console.log(start, end)
return differenceInCalendarDays(start, end);
}
Based on the provided information; you will need to parse the input dates before passing them to
differenceInCalendarDaysfunction. Something like:CODE DEMO