The date to check as a Date object or timestamp (number)
Interval object with start and end boundaries (can be null for open-ended intervals)
Optional
opts: BetweenOptionOptional configuration for boundary inclusion
Configuration options for the isBetween function. Controls how boundary dates are treated in the comparison.
Optional
bounds?: BoundsTypeSpecifies boundary inclusion using mathematical interval notation. Defaults to "()" for backward compatibility.
True if date is between the boundaries according to the bounds configuration, false otherwise
// Default behavior (exclusive boundaries)
const result = isBetween(
new Date(2024, 5, 15),
{ start: new Date(2024, 5, 10), end: new Date(2024, 5, 20) }
);
// Returns: true
// Inclusive boundaries
const result2 = isBetween(
new Date(2024, 5, 10),
{ start: new Date(2024, 5, 10), end: new Date(2024, 5, 20) },
{ bounds: "[]" }
);
// Returns: true (boundary is included)
// Open-ended interval (null end uses MAX_DATE)
const result3 = isBetween(
new Date(2025, 0, 1),
{ start: new Date(2024, 0, 1), end: null }
);
// Returns: true (any date after start)
// Works with timestamps
const result4 = isBetween(
Date.now(),
{ start: Date.now() - 1000, end: Date.now() + 1000 }
);
// Returns: true (within 1 second window)
// Invalid inputs return false
const result5 = isBetween(new Date("invalid"), { start: new Date(2024, 0, 1), end: new Date(2024, 11, 31) });
// Returns: false
bounds
option using mathematical interval notation:
Check if a date falls between two boundary dates with configurable inclusion.
This function checks whether a date falls within an interval defined by start and end boundaries. The inclusion of boundaries can be controlled using mathematical interval notation.