xxxxxxxxxx
// new Date("dateString") is browser-dependent and discouraged, so we'll write
// a simple parse function for U.S. date format (which does no error checking)
function parseDate(str) {
var mdy = str.split('/');
return new Date(mdy[2], mdy[0]-1, mdy[1]);
}
function datediff(first, second) {
// Take the difference between the dates and divide by milliseconds per day.
// Round to nearest whole number to deal with DST.
return Math.round((second-first)/(1000*60*60*24));
}
alert(datediff(parseDate(first.value), parseDate(second.value)));
xxxxxxxxxx
const getDaysDiffBetweenDates = (dateInitial, dateFinal) =>
(dateFinal - dateInitial) / (1000 * 3600 * 24);
// Example
getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')); // 9
xxxxxxxxxx
#Find the difference in days between two dates.
from datetime import date
start_date = date(2022, 1, 10)
end_date = date(2022, 11, 10)
(end_date - start_date).days
304
xxxxxxxxxx
const dayDif = (date1, date2) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000)
dayDif(new Date("2020-10-21"), new Date("2021-10-22"))
// Result: 366
xxxxxxxxxx
best way to get the number of days between these two dates
from datetime import date
d0 = date(2008, 8, 18)
d1 = date(2008, 9, 26)
delta = d1 - d0
print(delta.days)
xxxxxxxxxx
nbr_days = 365*year + year/4 - year/100 + year/400 + date + (153*month+8)/5
xxxxxxxxxx
const getDays = (dateInitial, dateFinal) => {
(dateFinal - dateInitial) / (1000 * 3600 * 24);
}
// Example
var startDate = new Date('2017-12-13');
var endDate = new Date('2017-12-22');
getDays(startDate, endDate); // 9
xxxxxxxxxx
const dayDiff = (date1: Date, date2: Date) => Math.ceil(Math.abs(date1.getTime() - date2.getTime()) / 86400000);