Skip to content

isBetween

The isBetween function checks if a date is between two other dates (inclusive or exclusive).

Syntax

typescript
isBetween(date: Date, start: Date, end: Date, inclusive?: boolean): boolean;

Parameters

NameTypeDescription
dateDateDate to be checked
startDateStart date of the interval
endDateEnd date of the interval
inclusiveboolean(Optional) If true, includes the start and end dates

Returns

TypeDescription
booleanTrue if the date is within the interval

Examples

typescript
isBetween(new Date("2024-06-10"), new Date("2024-06-01"), new Date("2024-06-30"));
// => true

isBetween(new Date("2024-06-01"), new Date("2024-06-01"), new Date("2024-06-30"), true);
// => true

Notes

  • Throws an error if any of the dates are not valid.
  • Useful for validating date ranges.

References

Released under the MIT License.