Home >>JavaScript Date Object Methods >JavaScript setDate() Method

JavaScript setDate() Method

JavaScript setDate() Method

JavaScript setDate() method is used to set the day of the month to the given input date object, created using date() constructor.

Syntax:
Date.setDate(day)

Parameter Values

Parameter Description
day This is a required parameter. It defines an integer representing the day of a month.

Browser Support

Method Chrome Edge Firefox Safari Opera
setDate() Yes Yes Yes Yes Yes
Here is an example of JavScript setDate() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
  var d = new Date();
  d.setDate(14);
  document.getElementById("demo").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1()
{
  var d = new Date("March 08, 2020 04:15:00");
  d.setDate(13);
  document.getElementById("demo1").innerHTML = d;
}
</script>
</body>
</html>
Output:

Click the button to see the Output.