Javascript Reference - JavaScript setDate() Method








setDate(date)
Sets the day of the month for the date. If the date is greater than the number of days in the month, the month value also gets increased.

Browser Support

setDate() Yes Yes Yes Yes Yes

Syntax

dateObject.setDate(day);




Parameter Values

Parameter Description
day Required. An integer representing the day of a month.

Expected values are 1-31, but other values are allowed.


0 will result in the last day of the previous month


-1 will result in the day before the last day of the previous month


If the month has 31 days, 32 will be the first day of the next month


If the month has 30 days, 32 will be the second day of the next month

Return Value

return a number, representing the number of milliseconds between the date object and midnight January 1 1970.





Example


var myDate = new Date();

myDate.setDate(12);
console.log(myDate.toString());

The code above generates the following result.