The setDate method sets the day of the month of the point in time stored in a Date object.
Besides, it can also be used to increase or decrease the point in time of that object in a given quantity of days.
The value returned by this method is the quantity of milliseconds passed since January 1st 1970 until the point in time stored in the Date object once it has been modified.
- days being an integer number that, when it is between 1 and the last day of the month in question (which can be 28, 29, 30, or 31), changes only the day of the month of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time of a Date object in a quantity equal to the range's limit being exceeded plus the remaining days.
- myDate being an object based on the Date object.
The following code uses the setDate method to change the day of the month of the current date. If the current day of the month is less than 15, it changes it to 28. On the other hand, if it is higher than 14, it changes it to 1: