Date/Since
1.38.0isBefore
Checks whether the first date occurs before the second date.
isBefore(dateLeft, dateRight):booleanParameters
dateLeftDaterequiredThe date to compare as the first value.
dateRightDaterequiredThe date to compare against.
Returns
booleantrue if dateLeft occurs before dateRight; otherwise, false.
Examples
01
Basic usage
Check whether one date is before another date.
TypeScript
import { isBefore } from "@cyref/js";
const dateLeft = new Date("2026-01-05");
const dateRight = new Date("2026-01-10");
const result = isBefore(dateLeft, dateRight);
console.log(result);
// true02
Date is not before
Returns false when dateLeft occurs after dateRight.
TypeScript
import { isBefore } from "@cyref/js";
const dateLeft = new Date("2026-01-10");
const dateRight = new Date("2026-01-05");
const result = isBefore(dateLeft, dateRight);
console.log(result);
// false03
Equal dates
Equal dates return false because the function checks for a strictly earlier date.
TypeScript
import { isBefore } from "@cyref/js";
const dateLeft = new Date("2026-03-15T12:00:00");
const dateRight = new Date("2026-03-15T12:00:00");
const result = isBefore(dateLeft, dateRight);
console.log(result);
// false04
Time is included in the comparison
The complete timestamp is compared, including hours, minutes, seconds, and milliseconds.
TypeScript
import { isBefore } from "@cyref/js";
const dateLeft = new Date("2026-06-10T09:30:00");
const dateRight = new Date("2026-06-10T15:30:00");
const result = isBefore(dateLeft, dateRight);
console.log(result);
// true05
Same day, different time
Two dates on the same calendar day can still produce different results based on their time.
TypeScript
import { isBefore } from "@cyref/js";
const morning = new Date("2026-08-20T09:00:00");
const evening = new Date("2026-08-20T18:00:00");
console.log(isBefore(morning, evening));
// true
console.log(isBefore(evening, morning));
// falseBuilt with@cyref/js·Official documentation