YouTip LogoYouTip

Jsref Setmonth

# JavaScript setMonth() Method ## Definition and Usage The setMonth() method sets the month (0-11) of a date object. **Note:** January is 0, February is 1, and so on up to December, which is 11. If the set month is greater than 11 or less than 0, the year will be handled accordingly. ## Browser Support | Method | Chrome | IE | Firefox | Safari | Opera | | setMonth() | Yes | Yes | Yes | Yes | Yes | ## Syntax ```date.setMonth(month,day)``` ## Parameter Values | Parameter | Description | | month | Required. An integer representing the month. Expected values are 0-11, but other values are allowed: | | | -1 will result in the last month of the previous year | | | 12 will result in the first month of the next year | | day | Optional. An integer representing the day of the 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 and you set the day parameter to 32, it will result in the first day of the next month | | | If the month has 30 days and you set the day parameter to 31, it will result in the first day of the next month | ## Return Value | Type | Description | | Number | The number of milliseconds between the date object and midnight on January 1, 1970 | ## Technical Details | DOM Version | Core | | --- | --- | ## More Examples ### Example 1 Set the month to April (3): ```javascript var d = new Date(); d.setMonth(3); ``` The result of *d* will be: ```javascript Mon Apr GMT+ ``` ### Example 2 Set the month to 15: ```javascript var d = new Date(); d.setMonth(15); ``` The result of *d* will be: ```javascript Mon Mar GMT+ ``` ### Example 3 Set the month to -1: ```javascript var d = new Date(); d.setMonth(-1); ``` The result of *d* will be: ```javascript Sun Dec GMT+ ```
← Jsref SetsecondsJsref Setminutes β†’