I need to find the difference between two dates. If the difference is greater than 6 then display a message in Java Script.
I tried below logic but somehow it is not working.
var sFromDate = new Date(Mon Jun 01 2020 00:00:00 GMT-0400);
var sToDate = new Date(Mon Nov 30 2020 23:59:59 GMT-0500);
var diff = sToDate.getTime() - sFromDate.getTime();
diff = diff / (1000 * 60 * 60 * 24 * 30);
if (diff > 6) {
alert('Not more than 6 months')
}
In the above example. I am still getting the alert even the range is within 6 months.
Can someone help me in finding the logic the difference between 2 dates should not be more than 6 months.