The first date as a Date object or timestamp (number)
The second date as a Date object or timestamp (number)
Optional
opts: { unit?: TimeUnit }Optional configuration object
Optional
unit?: TimeUnitThe unit of comparison (year, month, day, hour, minute, second, millisecond). Defaults to "millisecond"
True if date a
is equal to date b
, false otherwise or if either date is invalid
// Basic comparison (millisecond precision)
const date1 = new Date(2025, 0, 1, 12, 0, 0);
const date2 = new Date(2025, 0, 1, 12, 0, 0);
const result = isEqual(date1, date2);
// Returns: true
// Compare at day granularity
const result2 = isEqual(
new Date(2025, 0, 1, 9, 0),
new Date(2025, 0, 1, 17, 0),
{ unit: "day" }
);
// Returns: true (same day, different times)
// Works with timestamps
const timestamp = Date.now();
const result3 = isEqual(timestamp, new Date(timestamp));
// Returns: true
// Different dates return false
const result4 = isEqual(new Date(2025, 0, 1), new Date(2025, 0, 2));
// Returns: false
// Invalid dates return false
const result5 = isEqual(new Date("invalid"), new Date(2025, 0, 1));
// Returns: false
Check if two dates are equal.
This function compares two dates and returns true if they represent the same point in time. The comparison can be performed at different granularities (year, month, day, hour, minute, second, or millisecond).