Skip to content

Instantly share code, notes, and snippets.

@petergi
Created February 25, 2026 19:18
Show Gist options
  • Select an option

  • Save petergi/e9858f7d96ffc70552e16387bb577b9a to your computer and use it in GitHub Desktop.

Select an option

Save petergi/e9858f7d96ffc70552e16387bb577b9a to your computer and use it in GitHub Desktop.
Checks if the given date is a weekend. - Use `Date.prototype.getDay()` to check weekend by using a modulo operator (`%`). - Omit the argument, `d`, to use the current date as default.
// Checks if the given date is a weekend.
// - Use `Date.prototype.getDay()` to check weekend by using a modulo operator (`%`).
// - Omit the argument, `d`, to use the current date as default.
const isWeekend = (d = new Date()) => d.getDay() % 6 === 0;
isWeekend(); // 2018-10-19 (if current date is 2018-10-18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment