Friday, November 16, 2012

comparing javascript dates

I have two javascript dates and I want to know if they\’re the same date. The two dates can be for the same date but have different times: Date1 can be set for 3PM while Date2 can be set for 1AM.


I tried these two options but neither work:



// doesn\'t work when same date but different time
if (Date1.getTime() === Date2.getTime())

// gives true when dates are in different months
if (Date1.getUTCDate() === Date2.getUTCDate())


What the best way to get true when Date1 and Date2 are the same day, regardless of the actual time within the day?


Thanks.






Rating: 4 out of 5 based on 4 ratings



The post comparing javascript dates appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/comparing-javascript-dates.html

No comments:

Post a Comment