Determine if a date is a Saturday or a Sunday using JavaScript

Sure it is! The Date class has a function called getDay() which returns a integer between 0 and 6 (0 being Sunday, 6 being Saturday). So, in order to see if today is during the weekend:

var today = new Date();
if(today.getDay() == 6 || today.getDay() == 0) alert('Weekend!');

In order to see if an arbitrary date is a weekend day, you can use the following:

var myDate = new Date();
myDate.setFullYear(2009);
myDate.setMonth(7);
myDate.setDate(25);

if(myDate.getDay() == 6 || myDate.getDay() == 0) alert('Weekend!');

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)