Javascript Reference - JavaScript getDate() Method








getDate()
returns the day of the month (1 through 31) for the date.

Browser Support

getDate() Yes Yes Yes Yes Yes

Syntax

dateObject.getDate();

Parameters

None.

Return Value

A Number from 1 to 31 to represent the day of the month.





Example


var myDate = new Date();

console.log(myDate.getDate());

The code above generates the following result.

Example 2

The following code shows how to get the day of the month from a specific date.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">get</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  ww w.ja v a  2 s  .c o m-->
    var d = new Date("July 21, 1976 02:34:56");
    var n = d.getDate()
    document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>

The code above is rendered as follows: