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 after or equal to date b
, false otherwise or if either date is invalid
// Basic comparison (millisecond precision)
const result = isAfterOrEqual(new Date(2025, 0, 2), new Date(2025, 0, 1));
// Returns: true
// Equality returns true
const date = new Date(2025, 0, 1);
const result2 = isAfterOrEqual(date, date);
// Returns: true
// Compare at day granularity
const result3 = isAfterOrEqual(
new Date(2025, 0, 1, 23, 59),
new Date(2025, 0, 1, 0, 0),
{ unit: "day" }
);
// Returns: true (same day)
// Works with timestamps
const result4 = isAfterOrEqual(Date.now(), Date.now() - 1000);
// Returns: true (current time is after 1 second ago)
// Invalid dates return false
const result5 = isAfterOrEqual(new Date("invalid"), new Date(2025, 0, 1));
// Returns: false
Check if the first date is after or equal to the second date.
This function compares two dates and returns true if the first date is chronologically after or equal to the second date. The comparison can be performed at different granularities (year, month, day, hour, minute, second, or millisecond).