Comparing date objects in JavaScript using the == operator
Today I learnt that you can't compare two Date objects directly in JavaScript.
Using the default JavaScript Date object, you need to first reset the time in the date to zero, down to the milliseconds:
dateA.setHour(0,0,0,0) == dateB.setHour(0,0,0,0)
Source: http://stackoverflow.com/questions/492994/compare-dates-with-javascript
If using Moment.js, you can use the .diff method:
dateA.diff(dateB, 'days') == 0
Written by Wei-Meng Lee
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Date
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#