Skip to content

Function.isBefore

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / isBefore

Function: isBefore()

isBefore(date, compare, unit?): boolean

Defined in: Date/isBefore.ts:18

Returns true when date is strictly before compare at the given unit granularity. Without a unit, compares exact timestamps (millisecond precision). With a unit, both dates are truncated with startOf before comparison. Week boundaries follow Sunday-start local time, matching startOf.

Parameters

date

Date

Date to test

compare

Date

Date to compare against

unit?

DateBoundaryUnit

Granularity; omit for exact comparison

Returns

boolean

True when date is before compare

Example

isBefore(new Date(2025, 3, 15), new Date(2025, 3, 16)); // true
isBefore(new Date(2025, 3, 15, 1), new Date(2025, 3, 15, 23), "day"); // false
isBefore(new Date(2025, 3, 30), new Date(2025, 4, 1), "month"); // true

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally