15,905,504 members
1.00/5 (1 vote)
See more:
I have to calculate number of days between two dates but every month is of 30
30 x 12 = 360 ,

What I have tried:

```function diff_year_month_day(dt1, dt2)
{

var time =(dt2.getTime() - dt1.getTime()) / 1000;
var year  = Math.abs(Math.round((time/(60 * 60 * 24))/365.25));
var month = Math.abs(Math.round(time/(60 * 60 * 24 * 7 * 4)));
var days = Math.abs(Math.round(time/(3600 * 24)));
return "Year :- " + year + " Month :- " + month + " Days :-" + days;

}```
Posted
Updated 17-Mar-22 2:15am
Richard MacCutchan 17-Mar-22 8:14am
Not all months have 30 days.
Richard Deeming 18-Mar-22 5:19am
Every month except February has 30 days; it's just that some of them have more. :)
Richard MacCutchan 18-Mar-22 5:26am
One day I hope to learn how to speak and write proper English. :(

## Solution 1

Convert the date to a "day of year":
`monthOfYear * 30 + dayOfMonth`
Then include the year to make a "dayNumber" by multiplying the year by 360 and adding that.
Simple subtraction does the rest!