JavaScript compares the number of days between two dates and can return a negative value, indicating that the latter is greater than the former.
This function has passed the test under IE and firefox.
Java code
/**
Compares the number of days between two dates, which can be a negative value
**/
function DateDiff(sDate1, sDate2)
{ //sDate1 and sDate2 are in 2002-12-18 format
var aDate, oDate1, oDate2, iDays;
aDate = sDate1.split("-");
oDate1 = new Date(aDate[0],aDate[1]-1,aDate[2]);
aDate = sDate2.split("-");
oDate2 = new Date(aDate[0],aDate[1]-1,aDate[2]);
iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24);
if((oDate1 - oDate2)<0){
return -iDays;
}
return iDays;
-