187
rated 0 times
[
189]
[
2]
/ answers: 1 / hits: 105261
/ 15 Years ago, sat, july 25, 2009, 12:00:00
Is it possible to determine if a date is a Saturday or Sunday using JavaScript?
Do you have the code for this?
More From » date
Is it possible to determine if a date is a Saturday or Sunday using JavaScript?
Do you have the code for this?
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!');