How to check if two dates are the same day in JavaScript
By Flavio Copes
Learn how to check if two dates fall on the same day in JavaScript by comparing their getFullYear(), getMonth(), and getDate() values in a helper function.
To check if two dates fall on the same day in JavaScript, compare their year, month, and day values. JavaScript does not provide this functionality in its standard library, but it takes three method calls per date:
getDate()returns the daygetMonth()returns the monthgetFullYear()returns the 4-digits year
This is a simple function you can copy/paste to do the check:
const datesAreOnSameDay = (first, second) =>
first.getFullYear() === second.getFullYear() &&
first.getMonth() === second.getMonth() &&
first.getDate() === second.getDate()
Example usage:
const morning = new Date('2026-08-07T08:30:00')
const evening = new Date('2026-08-07T21:15:00')
datesAreOnSameDay(morning, evening) //true
datesAreOnSameDay(morning, new Date('2026-08-08T01:00:00')) //false
Why can’t I just compare the dates?
Dates are objects. The === operator compares object references, so two distinct date objects are never equal, even when they hold the same instant:
new Date('2026-08-07') === new Date('2026-08-07') //false
Comparing timestamps with getTime() doesn’t help either. That checks the exact millisecond, and two times on the same day are almost never the same millisecond.
That’s why we compare the three date parts individually. Note that getMonth() returns a zero-based month (January is 0), but since we compare both dates the same way, it doesn’t matter here.
A shorter alternative
toDateString() returns just the date portion, like 'Fri Aug 07 2026', dropping the time. Comparing those strings works too:
first.toDateString() === second.toDateString()
I prefer the explicit function, but this one is handy for a quick check.
Watch out for timezones
Here’s the pitfall. getFullYear(), getMonth() and getDate() all use the local timezone of the environment running the code.
A timestamp close to midnight can be Tuesday in Rome and still Monday in New York. If your dates come from a server as UTC timestamps, the same two dates can compare differently depending on where the code runs.
If you want to compare calendar days in UTC instead, use the UTC variants: getUTCFullYear(), getUTCMonth() and getUTCDate(). Decide which one you need before shipping, not after a bug report.
Related posts about js: