Date getDate() method with example in JavaScript

JavaScript Date getDate() method: Here, we are going to learn about the getDate() method of Date class with Example in JavaScript.
Submitted by IncludeHelp, on March 04, 2019

JavaScript Date getDate() method

getDate() method is a Date's class method and it is used to get the current day of the month.

It accepts nothing as the parameter and returns a value between 1 to 31 (based on the day of the month).

Syntax:

    var dt = new Date();
    dt.getDate();

Examples:

    Input:
    var dt = new Date();
    dt.getDate();
    
    Output:
    4 // if date is 04/any month/any year

JavaScript code to get the current day of the month using getDate() method

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var date = dt.getDate(); //getting day of the month
	//printing day
	document.write("Today's date is: " + date);
</script>
</body>
</html>

Output

Today's date is: 4

JavaScript Date Object Methods »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.