Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript setDate Method



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.


Syntax

myDate.setDate( days )

With:
  • 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.


Example

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:



Technical Details

The setDate method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.





JavaScript Manual >> Date Object >> setDate Method



This post first appeared on ROM Cartridge, please read the originial post: here

Share the post

JavaScript setDate Method

×

Subscribe to Rom Cartridge

Get updates delivered right to your inbox!

Thank you for your subscription

×