views:

890

answers:

3

hi there, i am new to javascript. my requirement is .. i want to popup a message on particular days(like sunday,monday..) all through when a date is selected. i tried getday() function but it didnot work. please suggest me. i am tired of searching google

+6  A: 
var date = new Date();
var day = date.getDay();

day now holds a number from zero to six; zero is Sunday, one is Monday, and so on.

So all that remains is to translate that number into the English (or whatever other language) string for the day name:

var name = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day];
Kieron
+1  A: 

This page seems to provide you with what you need.

What we are going to do is to add getMonthName() and getDayName() methods to all our dates so that we can get the month name or day name by calling these new methods directly instead of having to call getMonth() or getDay() and then do an array lookup of the corresponding name.

You can then do:

var today = new Date;
alert(today.getDayName());
Espo
A: 
var days= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var today = new Date();
document.write(days[today.getDay()]);
Vertigo