This article explains how to compare 2 Date Objects in Javascript

The best way to compare 2 Date objects using javascript is to get its long equivalent.

For example we have a date in this format: mm-dd-yyyy and we want to compare them. We will declare the javascript function this way:

function compareDate(a, b) {
 var temp, from, to;
 
 from = new Date();
 temp = a.split("-");
 from.setFullYear(temp[2], temp[0] - 1, temp[1]);
 
 to = new Date();
 temp = b.split("-");
 to.setFullYear(temp[2], temp[0] - 1, temp[1]);
 
 if(from.getTime() > to.getTime()) {
  return false;
 }
 return true;
}

For setFullYear's definition:
http://www.w3schools.com/jsref/jsref_setfullyear.asp
This article explains how to compare 2 Date Objects in Javascript This article explains how to compare 2 Date Objects in Javascript Reviewed by czetsuya on Sunday, October 25, 2009 Rating: 5

No comments:

Powered by Blogger.