Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
20

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!');

[#99061] Tuesday, July 21, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carlton

Total Points: 373
Total Questions: 123
Total Answers: 97

Location: Saint Helena
Member since Wed, Nov 9, 2022
2 Years ago
carlton questions
Sun, Apr 25, 21, 00:00, 3 Years ago
Wed, Feb 17, 21, 00:00, 3 Years ago
Tue, Oct 27, 20, 00:00, 4 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Mon, Apr 13, 20, 00:00, 4 Years ago
;