2 Example(s) of JavaScript getDate


Description :

JavaScript getDate function will return the day of the month and it will be used as date.getDate(). In the below example, we will display day in innerHTML of span tag using document.getElementById("sample").innerHTML = day;


JavaScript getDate Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>    
</head>
<body>
<button onclick="getDay()">Show me the Day</button>
<p id="sample"></p>
<script>
function getDay() {
    var date = new Date();
    var day = date.getDate();
    document.getElementById("sample").innerHTML = day;
}
</script>

</body>
</html>

Output

Description :

In this example, we are going to set the date in date variable as new Date("April 6, 1992 03:14:00") and then getDate of this method, which will return the day as 6.


JavaScript getDate Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="getDay()">Show me the day</button>
<p id="sample"></p>
<script>
function getDay() {
    var date = new Date("April 6, 1992 03:14:00");
    var day = date.getDate();
    document.getElementById("sample").innerHTML = day;
}
</script>
</body>
</html>

Output