Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript getDay() Method

JavaScript getDay() Method

Date Object Reference JavaScript Date object

Example

Return a number representing the day of the week.

var d = new Date();

var n = d.getDay();

n Output result:

var d=new Date() document.write(d.getDay())

Try it »


Definition and Usage

The getDay() method returns a number representing the day of the week (0 to 6).

Note: Sunday is 0, Monday is 1, and so on.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the getDay() method.


Syntax

Date

.getDay()

Return Value

Type Description
Number The return value is an integer between 0 (Sunday) and 6 (Saturday).

Technical Details

JavaScript version: 1.0

More examples

Example

Return the name of the day of the week (rather than a number):

var d=new Date();

var weekday=new Array(7);

weekday[0]="Sunday";

weekday[1]="Monday";

weekday[2]="Tuesday";

weekday[3]="Wednesday";

weekday[4]="Thursday";

weekday[5]="Friday";

weekday[6]="Saturday";

var n = weekday[d.getDay()];

n Output result:

Try it »


Date Object Reference JavaScript Date object