tags:

views:

234

answers:

3

Hi,

Just as the title says, any ideas?

Malcolm

EDIT: Oh, can you you supply code to do it please?

+1  A: 

Yes, it is possible, we can write a JavaScript code for that using JavaScript Date object.

Please use following JavaScript code.

var d = new Date()

document.write(d.getDay())

Umesh Aawte
+1  A: 

The Date class offers the getDay() Method that retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc)

var date = new Date();
switch(date.getDay()){
    case 0: alert("sunday!"); break;
    case 6: alert("saturday!"); break;
    default: alert("any other week day");
}
ONi
+7  A: 

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!');
Andrew Moore
Excellent answer, thankyou!
Malcolm
Note that it's better to set the date via: var myDate = new Date(2009, 7, 25); rather than setting it in three steps (not only does it avoid a few weird errors, but it is also more concise).
Steve Harrison
**@Steve:** I know, but for examples, it's usually better to be more verbose, in case someone doesn't know the order of the arguments.
Andrew Moore
@Andrew: Notice that in your example you're using the getDate function instead of getDay.
CMS
**@CMS:** Ouff, brain fart right there... Well, the text above had the proper answer. Corrected.
Andrew Moore