Recently, I was working on a customer dashboard for a retail client in New York where we needed to highlight today’s transactions differently. For a requirement, I wanted to check if a date is today.
In this tutorial, I will explain multiple practical methods to check if a date is today in TypeScript.
Method 1 – Using Date.toDateString()
The simplest and most readable way to check if a date is today in TypeScript is by comparing the string representations:
function isToday(date: Date): boolean {
const today = new Date();
return today.toDateString() === date.toDateString();
}
// Example usage
const orderDate = new Date('2025-04-27T14:30:00');
console.log(isToday(orderDate)); // true if today is April 27, 2025This method works because toDateString() returns only the date portion (e.g., “Sun Apr 27 2025”) without the time, making it perfect for day-level comparisons.
I frequently use this approach in dashboards where I need to highlight today’s appointments or orders quickly.
You can see the output in the screenshot below:

Check out Create a Date from Year, Month, and Day in TypeScript
Method 2 – Compare Year, Month, and Day
Sometimes you may want more explicit control. Here’s how to compare individual date components:
function isToday(date: Date): boolean {
const today = new Date();
return date.getFullYear() === today.getFullYear() &&
date.getMonth() === today.getMonth() &&
date.getDate() === today.getDate();
}
// Example with a sales transaction
const saleDate = new Date('2025-04-27T08:45:00');
if (isToday(saleDate)) {
console.log('This is a same-day transaction!');
}This approach is slightly more verbose but offers more clarity and can be easier to modify if you need to include additional checks.
Check out Add Months to a Date in TypeScript
Method 3 – Using setHours(0,0,0,0) for Date Reset
A more robust method is to reset both dates to midnight and then compare. Here is an example.
function isToday(date: Date): boolean {
const today = new Date();
// Reset hours, minutes, seconds, and milliseconds to zero
today.setHours(0, 0, 0, 0);
const compareDate = new Date(date);
compareDate.setHours(0, 0, 0, 0);
return today.getTime() === compareDate.getTime();
}
// Example with an investment transaction timestamp
const investmentTimestamp = new Date('2025-04-27T23:59:59');
console.log(isToday(investmentTimestamp)); // Checks if investment was made todayI’ve found this method particularly useful when working with banking applications where precise timestamp comparisons matter.
Check out Get the Current Date in TypeScript
Method 4 – Using Date Difference in Days
Another approach is to calculate the difference between dates in days:
function isToday(date: Date): boolean {
const today = new Date();
// Reset both dates to midnight
today.setHours(0, 0, 0, 0);
const compareDate = new Date(date);
compareDate.setHours(0, 0, 0, 0);
// Get difference in milliseconds and convert to days
const diffTime = Math.abs(compareDate.getTime() - today.getTime());
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
return diffDays === 0;
}
// Example with healthcare appointment
const appointmentDate = new Date('2025-04-27T15:30:00');
if (isToday(appointmentDate)) {
console.log('Your appointment is today!');
}This approach can be extended to check for “yesterday” or “tomorrow” by changing the comparison value.
Read How to Set a Date Value to Null in TypeScript
Method 5 – Using Date Libraries
For production applications, I often recommend using a date library like date-fns, which provides a clean API for date operations:
import { isToday } from 'date-fns';
// Example with an order delivery date
const deliveryDate = new Date('2025-04-27T16:00:00');
if (isToday(deliveryDate)) {
console.log('Your order will be delivered today!');
}Using date-fns not only makes your code more readable but also handles edge cases like timezone differences more reliably.
Handle Timezone Differences
One important consideration when checking if a date is today is handling timezones. If your application serves users across different time zones, you might need to adjust:
function isTodayInUserTimezone(date: Date, timezoneOffset: number): boolean {
// Get today in user's timezone
const userToday = new Date();
const userTimezoneOffset = userToday.getTimezoneOffset() * 60000;
const userTimeDate = new Date(userToday.getTime() - userTimezoneOffset + timezoneOffset);
// Format both dates to YYYY-MM-DD for comparison
const userTodayString = userTimeDate.toISOString().split('T')[0];
const dateString = new Date(date.getTime() - userTimezoneOffset + timezoneOffset)
.toISOString().split('T')[0];
return userTodayString === dateString;
}
// Example for a New York user (EST: UTC-5 or UTC-4 with DST)
// Offset in milliseconds (EST: -5 hours = -18000000 milliseconds)
const newYorkOffset = -18000000;
const webinarTime = new Date('2025-04-27T20:00:00Z'); // UTC time
console.log(isTodayInUserTimezone(webinarTime, newYorkOffset));This approach is particularly helpful for applications with international users or event scheduling features.
Read How to Get the Month from a Date in TypeScript
Common Issues to Avoid
Through my experience, I’ve encountered several common mistakes when comparing dates in TypeScript:
- Comparing full Date objects directly: This compares timestamps, not just the date portion
- Not accounting for timezones: A date might be “today” in one timezone but “tomorrow” in another
- String comparisons without standardization: Different date formats can lead to incorrect comparisons
You can follow the above points to fix those common issues.
I hope you learn how to check if a date is today in TypeScript using various methods. For simple applications, the toDateString() approach works well, while more complex use cases might benefit from date libraries or timezone-aware solutions.
If you have any questions or would like to share alternative approaches, please let me know in the comments below.

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.