CyrefJS
CCyrefJS
فا
Back to documentation
Date/Since 1.38.0

isBefore

Checks whether the first date occurs before the second date.

isBefore(dateLeft, dateRight):boolean

Parameters

dateLeftDaterequired

The date to compare as the first value.

dateRightDaterequired

The date to compare against.

Returns

boolean

true 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);
// true
02

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);
// false
03

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);
// false
04

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);
// true
05

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));
// false
Built with@cyref/js·Official documentation