The getDay() Method

The getDay() method returns the weekday as a number (0-6), but you can also use an array of names, and getDay() to display the weekday as a name:

HTML file: Displayed by browser:
<body>
<h4>The day of the week in numerical form:</h4>
<p id="demo"></p>
<h4>The day of the week spelled out:</h4>
<p id="days"></p>
<script>
var d = new Date(); //NUMERICAL FORM
document.getElementById("demo").innerHTML = d.getDay();
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
document.getElementById("days").innerHTML = days[d.getDay()];
</script>
</body>

The day of the week in numerical form:

The day of the week spelled out:

In JavaScript, the first of the week (0) means "Sunday", even if some countries in the world consider the first day of the week to be "Monday". 

BackTable of ContentsNext