How could I Count the number of days passed since beginning of the year to a specific date in Javascript?
I want to find the no of days elapsed from the starting of the year to a specific date in the year. How can I do that?
1 Answer
4 years ago by Divya
First get the current date and subtract the current date from the starting date of the year. Divide the result with milli seconds in one day
function days (d) {
return Math.ceil((new Date(d.getTime())-new Date(d.getFullYear(), 0, 1))/86400000);
}
console.log(days(new Date(2020, 4, 15)))
4 years ago by Divya