JavaScript Date getDay() Method

Definition and Usage

getDay() The method returns the day of the week for the specified date (from 0 to 6).

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

Example

Example 1

Returns the day of the week:

var d = new Date();
var n = d.getDay();

Try It Yourself

Example 2

Returns the name of the week (not just the 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()];

Try It Yourself

Syntax

Date.getDay()

Parameters

No parameters.

Technical Details

Return Value: Numbers, from 0 to 6, represent the day of the week.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
getDay() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor