Below is the example of Date getDay() method.
<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 document.write("Number of Day: " +Day); </script> |
Number of Day: 2
The 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. Day of the week will be returned in the form of integer value ranging from 0 to 6 means 0 for Sunday, 1 for Monday, and so on till 6 for Saturday.
More codes for the above method are as follows:
Program 1: 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.
<script> // Here a date has been assigned // While creating a Date object var A = new Date('July 1974'); var B = A.getDay(); // Printing day document.write("Number of Day: "+B); </script> |
Output:
Number of Day: 1
Program 2: The date of the month should must lie in between 1 to 31 because none of the month have date greater than 31 that is why it returns NaN i.e, not a number because date for the month does not exist.
<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. document.write(B); </script> |
Output:
NaN
Program 3: If nothing as parameter is given, it returns current day of the current week.
<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. document.write(B); </script> |
Output:
5
Supported Browsers: The browsers supported by JavaScript Date getDay() method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- How to check the input date is equal to today's date or not using JavaScript ?
- How to convert UTC date time into local date time using JavaScript ?
- JavaScript Date toLocaleTimeString() Method
- JavaScript Date UTC() Method
- JavaScript Date getHours() Method
- JavaScript Date getMinutes() Method
- JavaScript Date getMonth() Method
- JavaScript Date getSeconds() Method
- JavaScript Date getMilliseconds() Method
- JavaScript Date getFullYear() Method
- JavaScript Date getDate() Method
- JavaScript Date getUTCDate() Method
- JavaScript Date getUTCDay() Method
- JavaScript Date getUTCFullYear() Method
- JavaScript Date getUTCHours() Method
- JavaScript Date getUTCMilliseconds() Method
- JavaScript Date getUTCSeconds() Method
- JavaScript Date getUTCMinutes() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai


