One of the common requirements that I came across multiple projects is to compare two dates and identify which date is greater than the other. I have created a function which can be reused. The function recieves two input dates d1 and d2 and will return 1 if d1 is greater than d2 else return 0
{
var date1 = new Date(d1);
var date2 = new Date(d2);
var date1Month = ToInteger(date1.getMonth()+1);
var date1Day = ToInteger(date1.getDate());
var date1Year = ToInteger(date1.getFullYear());
var date2Month = ToInteger(date2.getMonth()+1);
var date2Day = ToInteger(date2.getDate());
var date2Year = ToInteger(date2.getFullYear());
if ((date1Year < date2Year)||((date1Year==date2Year)&&(date1Month < date2Month))||((date1Year==date2Year)&&(date1Month==date2Month)&&(date1Day < date2Day)))
return(0);
else
return(1);
}
Thanks Ajmal. This was really helpful.
ReplyDelete