Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Date.prototype.setFullYear

Sets the year, and optionally the month and day.

Available since: ES1

Syntax

date.setFullYear(year, monthIndex, day)

Parameters

ParameterTypeDescription
yearnumberThe year.
monthIndexnumberOptional. The month from 0 to 11.
daynumberOptional. The day of the month.

Return value

numberThe new timestamp. The object itself changes.

Examples

The same date a year later:

const date = new Date(2026, 2, 15);
date.setFullYear(date.getFullYear() + 1);
 
console.log(date.getFullYear(), date.getMonth(), date.getDate());

Output:

2027 2 15

Notes

Every set... method changes the object itself. If you still need the original date, copy it first: new Date(date).

See also

In the tutorial

  • Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.

Thanks for reading!

Donate to the site — we work hard for you.