15,662,426 members
1.00/5 (1 vote)
See more:
for example: Mai 6 (Without 2017) to Nov 7 (Without 2017) DAY:1, DAY:2, DAY:3..... And Nov 8 (Without 2017) to Mai 5 Next year (Without 2018) DAY:1, DAY:2, DAY:3..... I Have thish code but calculating the days only for this year and not from November 8 to next year Mai 5

What I have tried:

function getDays(strDay1, strDay2){ var day=1000*60*60*24;

strDay1 = strDay1 + ' ' + (new Date().getFullYear()); strDay2 = strDay2 + ' ' + (new Date().getFullYear());

var d1 = Date.parse(strDay1); var d2 = Date.parse(strDay2);

var diff = d2 - d1; return Math.round(diff/day) }

Posted
Updated 14-Feb-19 0:29am

## Solution 1

Use The Following Function in Javascript.

function getDays(strDay1, strDay2) {
debugger;
var strMonth1 = strDay1.split(' ')[0];
var strMonth2 = strDay2.split(' ')[0];
var months = { JAN: 1, FEB: 2, MAR: 2, APR: 4, MAY: 5, JUN: 6, JUL: 7, AUG: 8, SEP: 9, OCT: 10, NOV: 11, DEC: 12 };
Month1 = months[strMonth1.toUpperCase()];
Month2 = months[strMonth2.toUpperCase()];
if (Month1 > Month2)
{
strDay1 = strDay1 + ' ' + (new Date().getFullYear());
strDay2 = strDay2 + ' ' + (new Date().getFullYear()+1);
}
else
{
strDay1 = strDay1 + ' ' + (new Date().getFullYear());
strDay2 = strDay2 + ' ' + (new Date().getFullYear());
}
var day = 1000 * 60 * 60 * 24;

var d1 = Date.parse(strDay1); var d2 = Date.parse(strDay2);

var diff = d2 - d1; return Math.round(diff / day)
}