JavaScript getDay() Method
February 8, 2021 10:45 am IST
JavaScript getDay() Method The getDay()
method returns an integer number, between 0 (Sunday) and 6 (Saturday), corresponding to the day of the week for the given date.
Example <!DOCTYPE html>
<html >
<body >
<p >Click the button to display todays day of the week.</p >
<button onclick ="myFunction()" >Display Day</button >
<p id ="point" ></p >
<script >
function myFunction () {
var d = new Date ();
var n = d .getDay ()
document .getElementById ("point" ).innerHTML = n ;
}
</script >
</body >
</html >
Syntax Return Value Value Explanation Number Returns an integer number, between 0 (Sunday) and 6 (Saturday), corresponding to the day of the week for the given date.
Get Day Name from Current Date In the following example, we will get the Day Name of the weekday from a Current Date.
Example <!DOCTYPE html>
<html >
<body >
<p >Click the button to display todays day of the week.</p >
<button onclick ="myFunction()" >Display Day</button >
<p id ="point" ></p >
<script >
var arr = [];
arr [0 ] = "Sunday" ;
arr [1 ] = "Monday" ;
arr [2 ] = "Tuesday" ;
arr [3 ] = "Wednesday" ;
arr [4 ] = "Thursday" ;
arr [5 ] = "Friday" ;
arr [6 ] = "Saturday" ;
function myFunction () {
var d = new Date ();
var n = d .getDay ();
document .getElementById ("point" ).innerHTML = arr [n ];
}
</script >
</body >
</html >
Get Day from Specific Date In the following example, we will get the Day of the week from a specific date.
Example <!DOCTYPE html>
<html >
<body >
<p >Click the button to display day of the given date.</p >
<button onclick ="myFunction()" >Display Day</button >
<p id ="point" ></p >
<script >
function myFunction () {
var d = new Date ("May 19, 1995 02:30:25" );
var n = d .getDay ()
document .getElementById ("point" ).innerHTML = n ;
}
</script >
</body >
</html >
Get Day Name from Specific Date In the following example, we will get the name of the day of the week from a specific date.
Example <!DOCTYPE html>
<html >
<body >
<p >Click the button to display day of the given date.</p >
<button onclick ="myFunction()" >Display Day</button >
<p id ="point" ></p >
<script >
var arr = [];
arr [0 ] = "Sunday" ;
arr [1 ] = "Monday" ;
arr [2 ] = "Tuesday" ;
arr [3 ] = "Wednesday" ;
arr [4 ] = "Thursday" ;
arr [5 ] = "Friday" ;
arr [6 ] = "Saturday" ;
function myFunction (){
var d = new Date ("May 19, 1995 02:30:25" );
var n = d .getDay ();
document .getElementById ("point" ).innerHTML = arr [n ];
}
</script >
</body >
</html >
Reminder Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript .
Please do google search for:
Join Our Channel Join our telegram channel to get an instant update on depreciation and new features on HTML , CSS , JavaScript , jQuery , Node.js , PHP and Python .
This channel is primarily useful for Full Stack Web Developer.
Share this Page Meet the Author