+ 1
Update :- trying to calculate months between two dates in javascript? pls check the following js file. Also please remember
var userdateObj1 = new Date(userdate1); var userdateObj2 = new Date(userdate2); // window.alert ("userdateObj is: "+userdateObj); var msPerDay = 24 * 60 * 60 * 1000; var userdateObjmSeconds1 = userdateObj1.getTime(); var userdateObjmSeconds2 = userdateObj2.getTime(); var totalmonthsleft; var totaldaysLeft; if (userdateObjmSeconds1 < userdateObjmSeconds2){ totaldaysLeft = Math.ro
4 Respuestas
+ 4
With your code, you miss the monthes between the two date. For me, you have to code :
DateTo.getMonth() - DateFrom.getMonth() + (12 * (DateTo.getFullYear() - DateFrom.getFullYear()));
You will perhaps also add 1 if you include or not the From month.
0
If you mind speed over accuracy, here's a code that gets the number of months with less than 3 day error for dates less than 100 years apart
Edit: added a second ratio ("ratioover100") which is more accurate for the long times, but may give worse accuracy in short ones.
https://code.sololearn.com/WRIE9AEGh4If/?ref=app
0
GUYS PLEEASE CHECK AND TELL ME HOW TO get on with it
0
[SOLVED]