Checking if two Dates have the same date info

Hellnar picture Hellnar · Dec 13, 2010 · Viewed 84k times · Source

How can I check if two different date objects have the same date information(having same day, month, year ...)? I have tried "==", "===" and .equals but none seems to work.

Answer

Felix Kling picture Felix Kling · Dec 13, 2010

You can use valueOf() or getTime():

a = new Date(1995,11,17);
b = new Date(1995,11,17);

a.getTime() === b.getTime() // prints true