JavaScript setFullYear(): Change the Year of a Date

Date.prototype.setFullYear() changes the year of an existing Date in local time. It can also set the month and day in the same call, mutates the Date object, normalizes out-of-range values, and returns the updated timestamp.

Syntax:

date.setFullYear(year);
date.setFullYear(year, monthValue);
date.setFullYear(year, monthValue, dateValue);

A simple year change:

const date = new Date(2026, 8, 10);
date.setFullYear(2030);
console.log(date.getFullYear()); // 2030

Setting Only the Year Top ↑

When only the year is supplied, the current month, day and time components remain in place where possible.

const date = new Date(2026, 3, 5, 9, 30);
date.setFullYear(2015);
console.log(date.toString());

Setting Year, Month and Day Together Top ↑

The optional second and third arguments use the same rules as the numeric Date constructor: months are zero-based and the day is the day of the month.

const date = new Date();
date.setFullYear(2028, 1, 29); // 29 Feb 2028
console.log(date.toDateString());

Adding or Subtracting Years Top ↑

Read the current year with getFullYear(), then set the adjusted year.

const date = new Date();
date.setFullYear(date.getFullYear() + 10);
console.log(date);

What Happens to February 29? Top ↑

Be careful when adding years to a leap-day date. If the target year does not have February 29, JavaScript normalizes the result into March.

const leapDay = new Date(2028, 1, 29);
leapDay.setFullYear(2029);
console.log(leapDay.toDateString()); // Thu Mar 01 2029

If your business rule means “last valid day of February,” detect and clamp that case explicitly.

Overflow in Month and Day Arguments Top ↑

Optional month/day values are normalized. Month 12 becomes January of the next year; day 0 means the final day of the previous month.

const date = new Date(2026, 0, 15);
date.setFullYear(2026, 12, 1);
console.log(date.toDateString()); // Fri Jan 01 2027

Return Value and Mutation Top ↑

const date = new Date();
const timestamp = date.setFullYear(2035);
console.log(typeof timestamp); // "number"
console.log(date.getFullYear()); // 2035

Using setUTCFullYear() Top ↑

setFullYear() interprets the components in local time. Use setUTCFullYear() when your calculation is defined in UTC.

const date = new Date("2026-12-31T23:30:00Z");
date.setUTCFullYear(2030);
console.log(date.toISOString());

setYear() vs setFullYear() Top ↑

Use setFullYear() for modern code. The older setYear() method has legacy handling for years 0–99 and should not be used for new work.

Common setFullYear() Mistakes Top ↑

  • Forgetting that optional months are zero-based.
  • Assuming February 29 remains February 29 in a non-leap target year.
  • Expecting a new Date rather than mutation.
  • Using local setters when the requirement is explicitly UTC.

Next: setHours() Date Reference




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer