Possible Duplicate:
Get difference between 2 dates in javascript?
I am storing date variables like this:
var startYear = 2011;
var startMonth = 2;
var startDay = 14;
Now I want to check if current day (today) is falling within 30 days of the start date or not.
Can I do this?
var todayDate = new Date();
var startDate = new Date(startYear, startMonth, startDay+1);
var difference = todayDate - startDate;
????
I am not sure if this is syntactically or logically correct.
In JavaScript, the best way to get the timespan between two dates is to get their “time” value (number of milliseconds since the epoch) and convert that into the desired units. Here is a function to get the number of days between two dates: