The first date as a Date object or timestamp (number)
The second date as a Date object or timestamp (number)
True if both dates are on the same day, false otherwise or if either date is invalid
// Same day, different times
const result = isSameDay(
new Date(2024, 5, 15, 0, 0),
new Date(2024, 5, 15, 23, 59)
);
// Returns: true
// Different days
const result2 = isSameDay(
new Date(2024, 5, 15, 23, 59),
new Date(2024, 5, 16, 0, 0)
);
// Returns: false
// Same day, different times (with seconds)
const result3 = isSameDay(
new Date(2024, 5, 15, 14, 30, 45),
new Date(2024, 5, 15, 9, 15, 20)
);
// Returns: true
// Works with timestamps
const today = new Date(2024, 5, 15);
const result4 = isSameDay(today.getTime(), today);
// Returns: true
// Invalid dates return false
const result5 = isSameDay(new Date("invalid"), new Date(2024, 5, 15));
// Returns: false
Check if two dates are on the same calendar day.
This function compares two dates and returns true if they fall on the same calendar day, regardless of time components.