JavaScript Date setFullYear() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Date

Definition

Date.prototype.setFullYear() changes the year (and optionally month and day) of a Date according to local time. It mutates the object in place and returns the new epoch milliseconds.

Remember
date.setFullYear(year)
date.setFullYear(year, monthIndex)
date.setFullYear(year, monthIndex, day)

year       = full year (e.g. 1995, 0, 2026)
monthIndex = 0–11 (optional; Jan = 0)
day        = 1–31 (optional; requires month)

→ mutates date
→ returns new epoch ms (or NaN if invalid)

Syntax

Call date.setFullYear. Start with this line.

JavaScript
date.setFullYear(y[, m[, day]])
CallWhat it does
date.setFullYear(y[, m[, day]])Primary signature.
date.setFullYear(...)Call with the arguments your case needs.

Built into JavaScript. Call setFullYear(...) on a Date instance — no import required.

Library declarations
JavaScript
date.setFullYear(y[, m[, day]])

Parameters

ParameterDescription
yearValueRequired. Full year to write
monthValueOptional. Month index 0–11
dateValueOptional. Day of month; requires monthValue

Return Value

Return ValueDescription
*The value returned by date.setFullYear().

JavaScript Examples

Example 1 — Set the Year

Change only the local year; month and day stay the same.

JavaScript
const event = new Date("August 19, 1975 23:15:30");
event.setFullYear(1969);

console.log(event.getFullYear()); // 1969
Try It Yourself

How It Works

  1. Start with a date. August 19, 1975 is the baseline.
  2. Write the year. setFullYear(1969) updates only the year.
  3. Keep month/day. August 19 remains; only the year changes.
  4. Read it back. getFullYear() returns 1969.

Example 2 — Year, Month, and Day Together

Pass optional month and day to set a full local calendar date in one call.

JavaScript
const d = new Date(2026, 0, 15);
d.setFullYear(2030, 5, 20); // June 20, 2030

console.log(d.getFullYear()); // 2030
console.log(d.getMonth());    // 5
console.log(d.getDate());     // 20
Try It Yourself

How It Works

  1. Three arguments. Year, month index, and day update together.
  2. Month index. 5 means June (January is 0).
  3. Day requires month. If you pass day, you must also pass month (MDN).
  4. One mutation. A single call replaces all three local fields.

Example 3 — Leap Day into a Non-Leap Year

Feb 29 rolls forward when the new year is not a leap year.

JavaScript
const d = new Date(2024, 1, 29); // Feb 29, 2024
d.setFullYear(2025);

console.log(d.getFullYear()); // 2025
console.log(d.getMonth());    // 2 (March)
console.log(d.getDate());     // 1
Try It Yourself

How It Works

  1. Leap day start. February 29 exists in 2024.
  2. Change year only. Month/day stay Feb 29 conceptually.
  3. Normalize. 2025 has no Feb 29 → March 1.
  4. Check fields. Year 2025, month 2, day 1.

Browser & Runtime Support

Date.prototype.setFullYear() is part of the language from early ECMAScript and is Baseline Widely available (MDN).

✓ Baseline · Widely available

Date.prototype.setFullYear()

Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.

99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.setFullYear() Excellent

Bottom line: Safe everywhere. Focus on leap-day overflow and local vs UTC choice rather than feature detection.

Frequently Asked Questions

It sets the year of a Date in local time. You can also pass optional month (0–11) and day arguments. The Date is mutated in place and the method returns the new epoch milliseconds.
Yes. setFullYear(year, monthIndex, day) updates year, month, and day together. If you pass day, you must also pass month.
getFullYear() reads the local year. setFullYear(year) writes a new year. They are the read/write pair for four-digit years.
JavaScript normalizes overflow. Feb 29, 2024 becomes March 1, 2025 when you call setFullYear(2025) without changing month/day.
No. It returns a number (epoch milliseconds). Do not chain another setter on the return value.
setFullYear() changes the local calendar year. setUTCFullYear() changes the UTC calendar year. Prefer UTC setters for timezone-agnostic logic.

Next: setHours()

Learn how to set the hour (and optional minutes/seconds) on a Date.

setHours() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful