JavaScript getDay Function

The JavaScript getDay function is one of the date functions, which is useful for returning the day of the week number from a given date. The value returned by this getDay is between 0 and 6 based on the locale system settings.

getDay() syntax

The syntax of the JavaScript getDay() function is

dateObject.getDay()

Parameters: This function does not accept any parameters.

Return Value: The getDay() function returns an integer value representing the day of the week from a given date. The day of the week integer value ranges from 0 to 6.

  • 0 = Sunday
  • 1 = Monday
  • 2 = Tuesday
  • 3 = Wednesday
  • 4 = Thursday
  • 5 = Friday
  • 6 = Saturday

NOTE: If we use the getDay() function against an invalid date, it will return NaN.

JavaScript getDay Example

The following example helps you understand the getDay Function. Here, we use getDay to return the day number (day of the Week number) from the current date and time.

let dt = new Date();
console.log("Date = ",dt);
console.log("Day of the week =", dt.getDay());
Date = 2026-06-05T08:48:57.913Z
Day of the week = 5

Example 2: Get the day of the week from a custom Date

In this JavaScript example, we created a custom date and time. Next, we use the getDay() function to extract the day of the week number from the custom date.

let dt = new Date('January 22, 2020 10:09:07');
console.log("Date = ",dt);
console.log("Day of the week =", dt.getDay());
Date =  2020-01-22T04:39:07.000Z
Day of the week = 3

Example 3: Using JavaScript getDay() on an invalid date

When we use the getDay() function on an invalid date, it returns NaN. In the example below, we used January 39, which does not exist. If you replace the complete date part ‘January 39, 2020’ with ‘Hi’, it returns NaN.

let dt = new Date('January 39, 2020');
console.log(dt.getDay());
NaN

Example 4: Checking for the weekend

In the following example, we use the getDay() function to check whether the day is a weekend or not. As we all know, if the day of the week is 0 (Sunday) or 6 (Saturday), it is a weekend. For this, we must use the if else statement to check for the condition.

let dt = new Date('January 25, 2025');
let day = dt.getDay()
if (day == 0 || day == 6){
    console.log("Its a Weekend");
}
else {
    console.log("Its a Weekday!");
}
Its a Weekend

How to get the day of the week in words using JavaScript?

With the help of JavaScript getDay() and an array of names from Sunday to Saturday, we can show the name rather than the day of the week number. To find the day of the month, use the getDate() function.

const days = [
  'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  'Thursday', 'Friday', 'Saturday'];

const dt = new Date();
console.log("Date =", dt);
console.log(days[dt.getDay()]);
Date = 2026-06-05T09:05:59.720Z
Friday

Otherwise, use the single line statement in modern code block to get the same result.

console.log(dt.toLocaleString('en-US', { weekday: 'long' }));  

JavaScript getDay returns the wrong day

In the following example, we used the ‘2026-05-10’ string date, and the getDay() function returns the previous day (the last day of the week). When you check the calendar, May 10th is Sunday, but it returns Saturday.

Here, when parsing the string date and converting to a date object, it uses the local time zone, and the system is in the Alaska Daylight time zone (9 Hours before), it returns the previous date.

let dt = new Date('2026-05-10');
console.log(dt.getDay());
console.log(dt);
6 
Sat May 09 2026 16:00:00 GMT-0800 (Alaska Daylight Time)

What is the difference between getDay() and getDate() in JavaScript?

By seeing the names, both getDay() and getDate() functions are similar. However, they both serve different purposes and return different results.

  • getDay(): It returns the day of the week from 0 (Sunday) to 6 (Saturday).
  • getDate(): It returns the day of the month from 0 to 31.

The following example helps you understand the difference between the getDay() and getDate() functions.

let dt = new Date();
console.log(dt.toDateString());
console.log(dt.getDay());
console.log(dt.getDate());
Thu Jun 11 2026 
4 
11