TypeScript

isWithinInterval — Date Range Check

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Inclusive check that a date falls between two boundaries. Tiny but constantly useful for filtering rows by date range, validating bookings, etc.
TypeScript
Raw
export function isWithinInterval(date: Date, start: Date, end: Date): boolean {
  const t = date.getTime();
  const lo = Math.min(start.getTime(), end.getTime());
  const hi = Math.max(start.getTime(), end.getTime());
  return t >= lo && t <= hi;
}

isWithinInterval(new Date('2025-03-15'), new Date('2025-03-01'), new Date('2025-03-31'));  // true
isWithinInterval(new Date('2025-04-01'), new Date('2025-03-01'), new Date('2025-03-31'));  // false
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.