How to determine if a date is today in JavaScript
By Flavio Copes
Learn how to determine if a Date is today in JavaScript by comparing its getDate(), getMonth(), and getFullYear() values against a fresh new Date() instance.
How can you determine if a JavaScript Date object instance is a representation of a date/time that is “today”? You compare its day, month and year against a fresh new Date() instance.
Given a Date instance, we can use the getDate(), getMonth() and getFullYear() methods, which return the day, month and year of a date, and compare them to today, which can be retrieved using new Date().
Here’s a small function that does exactly that, returning true if the argument is today:
const isToday = (someDate) => {
const today = new Date()
return someDate.getDate() === today.getDate() &&
someDate.getMonth() === today.getMonth() &&
someDate.getFullYear() === today.getFullYear()
}
You can use it like this:
const flightDate = new Date('2026-08-07T15:30:00')
isToday(flightDate) //true, if you run this on August 7, 2026
Why not compare the dates directly?
You might be tempted to write someDate === new Date(). That never works. Date objects are compared by reference, so two distinct Date objects are never equal, even when they hold the same instant.
Comparing timestamps with getTime() doesn’t help either. “Today” is not a single instant. Two dates on the same day almost always carry different times, so their timestamps differ.
That’s why we compare year, month and day, and ignore hours and minutes.
A shorter alternative
toDateString() returns just the date part of a Date, like 'Fri Aug 07 2026'. Comparing those strings does the same job in one line:
const isToday = (someDate) => {
return someDate.toDateString() === new Date().toDateString()
}
I find the first version more explicit, but both are fine.
Watch out for time zones
Both approaches use the local time zone of the machine running the code.
Take a date created from a UTC string:
const meeting = new Date('2026-08-08T00:30:00Z')
For a user in Rome that’s 2:30 AM on August 8. For a user in New York it’s still 8:30 PM on August 7. isToday(meeting) gives each of them a different answer, and both are correct for their own time zone.
This matters on servers, too. Your server might run in UTC while your users don’t. If “today” must mean a specific time zone, decide which one first, and compare the dates in that zone.
Check out the JavaScript Date guide to find out more how to handle the Date object, if you need.
Related posts about node: