Files
30-seconds-of-code/snippets/js/s/is-between-dates.md
2023-05-07 16:07:29 +03:00

648 B

title, type, language, tags, cover, dateModified
title type language tags cover dateModified
Check if date is between two dates snippet javascript
date
flower-portrait-6 2020-10-20T23:02:01+03:00

Checks if a date is between two other dates.

  • Use the greater than (>) and less than (<) operators to check if date is between dateStart and dateEnd.
const isBetweenDates = (dateStart, dateEnd, date) =>
  date > dateStart && date < dateEnd;
isBetweenDates(
  new Date(2010, 11, 20),
  new Date(2010, 11, 30),
  new Date(2010, 11, 19)
); // false
isBetweenDates(
  new Date(2010, 11, 20),
  new Date(2010, 11, 30),
  new Date(2010, 11, 25)
); // true