Home >>JavaScript Date Object Methods >JavaScript getDay() Method

JavaScript getDay() Method

JavaScript getDay() Method

JavaScript getDay() method is used to return the day of the week for the given input date. It returns an integer value between 0 to 6 where 0 is for Sunday and 1 is for Monday.

Syntax:
Date.getDay()

Browser Support

Method Chrome Edge Firefox Safari Opera
getDay() Yes Yes Yes Yes Yes
Here is an example of JavaScript getDay() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
  var d = new Date();
  var n = d.getDay()
  document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() 
{
  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()];
  document.getElementById("demo1").innerHTML = n;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.