Skip to content
Related Articles

Related Articles

JavaScript Date getDay() Method

Improve Article
Save Article
  • Last Updated : 29 Nov, 2022
Improve Article
Save Article

The JavaScript Date getDay() Method is used to fetch the day of a week(0 to 6) from a given Date object.

Syntax: 

DateObj.getDay()

Parameter: This method does not accept any parameters.

Return Values: It returns the day of the week for the given date. The day of the week will be returned in the form of an integer value ranging from 0 to 6 means 0 for Sunday, 1 for Monday, and so on till 6 for Saturday.

Below is an example of the Date.getDay() method. 

Example 1: 

javascript




<script>
    // Here a date has been assigned 
    // while creating Date object
    var A = new Date('October 15, 1996 05:35:32');
  
    // Day of the week from above Date Object is
    // being extracted using getDay()
    var Day = A.getDay();
  
    // Printing day of the week
    console.log("Number of Day: " +Day);
</script>

Output: 

Number of Day: 2

More codes for the above method are as follows:

Example 2: If the date of the month is not given, by default the function considers it as the first date of the month and hence accordingly it returns the day of the week. It is an exceptional case. 

javascript




<script>
    // Here a date has been assigned 
    // While creating a Date object
    var A = new Date('July 1974');
       
    var B = A.getDay();
       
    // Printing day
    console.log("Number of Day: "+B);
</script>

Output: 

Number of Day: 1

Example 3: The date of the month should lie between 1 to 31 because none of the months have a date greater than 31 that is why it returns NaN i.e, not a number because the date for the month does not exist. 

javascript




<script>
    // Here a date has been assigned 
    // while creating Date object
    var A = new Date('October 35, 1996 05:35:32');
      
    // Day of the week from above Date Object
    // is being extracted using getDay()
    var B = A.getDay();
      
    // Printing day of the week.
    console.log(B);
</script>

Output: 

NaN

Example 4: If nothing as a parameter is given, it returns the current day of the current week. 

javascript




<script>
    // Creating Date Object
    var A = new Date();
      
    // day of the week from above object
    // is being extracted using getDay().
    var B = A.getDay()
      
    // Printing day of the week.
     console.log(B);
</script>

Output: It returns the current day of the week.

5

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.

Supported Browsers: The browsers supported by JavaScript Date.getDay() method are listed below: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 3 and above
  • Opera 3 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!