Solved: javascript difference between two dates

The main problem related to the difference between two dates is that they may not be in the same time zone.

var date1 = new Date(2018, 11, 24);
var date2 = new Date(2018, 11, 30);
var diffDays = date2.getDate() - date1.getDate();

This code is creating two new Date objects, one for December 24th, 2018 and one for December 30th, 2018. It is then finding the difference in days between those two dates using the .getDate() method.

Math with dates

var date = new Date(); // 1/1/0001 var date2 = new Date(); // 12/31/9999

Related posts:

Leave a Comment