The JavaScript Date object can help here.
The first step is to convert these strings to Date instances. This is easy to do:
var str = "06/07/2012"; // Eg, "mm/dd/yyyy"; var dt = new Date(parseInt(str.substring(6), 10), // Year parseInt(str.substring(0, 2), 10) - 1, // Month (0-11) parseInt(str.substring(3, 5), 10)); // Day
Then you can do all kinds of useful calculations. JavaScript dates understand leap years, etc. They use the idealized “day” concept, which is exactly 86,400 seconds. Their basic value is the number of milliseconds since the Age (midnight, January 1, 1970); this may be a negative number for dates prior to the era.
Read more on the MDN page on Date .
You can also use a library like MomentJS , which will help with parsing, performing date maths, formatting ...
TJ Crowder Jun 07 2018-12-12T00: 00Z
source share