Js - Compare Which Date Is Older
I want to compare two dates as which is bigger in those dates. var date1 = 2011-9-2; var date1 = 2011-17-06; Can anybody say how can I do this?
Solution 1:
You'll need to convert both strings to date objects first.
var date1 = newDate('2011-09-02');//yyyy-mm-dd formatvar date2 = newDate('2011-06-17');
if(date1 > date2){
alert('date1 is bigger than date2');
}
Once you have the 2 variables as date objects you can compare them against each other (without needing to convert to milliseconds/minutes/?)
Solution 2:
Check this link
And then do something like this:
var days = 0;
var difference = 0;
Christmas = newDate("December 25, 2005");
today = newDate();
difference = Christmas - today;
days = Math.round(difference/(1000*60*60*24));
Solution 3:
Create Date objects from your two values (check this link) and use that to do the comparison.
Post a Comment for "Js - Compare Which Date Is Older"