Skip to content

Find out if a date falls on weekend using JavaScript

To find out if a date falls on a weekend, get the day from the date object and see if it’s either 6 or 0 (6 is for Saturday, 0 is for Sunday).

Advertisements
let isWeekend = [6,0].includes(new Date("2020-10-17").getDay());
console.log(isWeekend? "Given date is on weekend!":"Given data is not on weekend!");
//Given date is on weekend!


isWeekend = [6,0].includes(new Date("2020-10-21").getDay());
console.log(isWeekend? "Given date is on weekend!":"Given data is not on weekend!");
//Given date is not on weekend!
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.