JavaScript getDate() | Find Day of the Month (1-31)

The JavaScript getDate() method is used when we need to get the day of the month which will be from 1 to 31. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

   <script>
      const d = new Date();
      let day = d.getDate();
      document.getElementById("xyz").innerHTML = day;
   </script>
	
</body>
</html>
Output

JavaScript getDate() Syntax

The syntax of getDate() method in JavaScript is:

x.getDate()

The x refers to an object of the Date() constructor.

The getDate() method returns a number from 1 to 31.

Get Current Day of the Month in JavaScript

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p>Current Date: <span id="res"></span></p>

   <script>
      const d = new Date();
      let day = d.getDate();
      document.getElementById("res").innerHTML = day;
   </script>

</body>
</html>
Output

Current Date:

Please note: To display date in format dd-mm-yyyy, refer to its separate example.

Please note: To display time in format hh:mm:ss, refer to its separate example.

Please note: To display time in format hh:mm:ss AM/PM, refer to its separate example.

JavaScript Online Test


« Previous Tutorial Next Tutorial »