JavaScript Date setFullYear()
Description
setFullYear()
sets the year of a date.
setFullYear()
can also set month and day.
Example 2
setFullYear()
can also set month and day.
const d = new Date("2025-01-15");
d.setFullYear(2020, 10, 3);
Try it Yourself »
d.setFullYear(2020, 10, 3);
Example 3
Set the date to six months ago:
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Try it Yourself »
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Syntax
Date.setFullYear(year, month, day)
Parameters
year
Required.
The year. Negative values are allowed.
The year. Negative values are allowed.
month
Optional.
The month (0 to 11).
The month (0 to 11).
Higher and lower values are handeled with date maths:
- -1 will result in the last month of the previous year
- 12 will result in the first month of the next year
- 13 will result in the second month of the next year
day
Optional.
The day (0 to 31).
The day (0 to 31).
Higher and lower values are handeled with date maths:
- 0 gives the last day of the previous month
- -1 gives the day before the last day of the previous month
- 32 gives the first day of the next month (if 31 days)
- 41 gives the tenth day of the next month (if 31 days)
Return Value
NONE
Changes the Date object in place.
Browser Support
setFullYear()
is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |