Click here to Skip to main content
15,886,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to do date comparison.
One condition is a date entered is greater than current date and date entered is less than a date+ 60 days

Second condition is entered date is not equal to already existing date


This is the formatting i have done for all dates
JavaScript
var auditDate = new Date(dString[2], dString[1] - 1, dString[0]);
auditDate.setDate(auditDate.getDate());
  if (auditDate && auditDate !=currentAuditDate)
{
//do something here
}


but its entering the if , even thought audit date and currentauditdate are same.
Both values being Mon Jan 19 00:00:00 UTC+5:30 2015

Can anyone please suggest a way to compare dates

Thanks
Arjun M
Posted

1 solution

Try comparing the .valueOf() values for the dates:
JavaScript
if (auditDate && auditDate.valueOf() !== currentAuditDate.valueOf()){
    // do something here...
}
 
Share this answer
 
Comments
Arjun Menon U.K 27-Jan-15 12:55pm    
Hi Richard,
Will try and let you know :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900