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