JavaScript Date setFullYear() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Local year setter

What You’ll Learn

setFullYear() writes the four-digit year on a Date object in local time, with optional month and day overload. This guide covers syntax, increment patterns, leap-year normalization, and comparisons with UTC setters.

01

Syntax

setFullYear(y)

02

Overload

y, m, d

03

Mutates

In place

04

+ 1 year

getFullYear

05

Leap day

Normalizes

06

Returns

Epoch ms

Introduction

Renewals, birthdays, and fiscal rollovers often need to bump a date by one year or snap to a specific calendar day. After reading the year with getFullYear(), setFullYear() is the local-time setter that writes it back.

Like other Date setters, it mutates the original object. Clone with new Date(date) when you must keep the previous instant.

Understanding the setFullYear() Method

Date.prototype.setFullYear(year [, monthIndex [, day]]) accepts a four-digit year and optional zero-based month and day. When you pass only the year, month and day stay the same—unless normalization is required (for example Feb 29 in a non-leap year).

The method returns epoch milliseconds, not the Date object. Call each setter on the same Date variable when you need multiple changes—do not chain on the numeric return value.

💡
Beginner Tip

To add one year: date.setFullYear(date.getFullYear() + 1). For a full calendar date in one call: date.setFullYear(2027, 6, 15) sets July 15, 2027.

📝 Syntax

JavaScript
dateObj.setFullYear(year)
dateObj.setFullYear(year, monthIndex)
dateObj.setFullYear(year, monthIndex, day)

Parameters

  • year — Four-digit integer (e.g. 2027).
  • monthIndex (optional) — Zero-based month 0–11 (January = 0).
  • day (optional) — Day-of-month 1–31; requires monthIndex when provided.

Return value

  • Updated epoch milliseconds after the change.
  • NaN if the Date was invalid before the call.

⚡ Quick Reference

GoalCode
Set year onlydate.setFullYear(2027)
Set year + month + daydate.setFullYear(2027, 6, 15)
Add one yeardate.setFullYear(date.getFullYear() + 1)
Read year after setdate.getFullYear()
UTC year setterdate.setUTCFullYear(2027)
Clone before mutateconst copy = new Date(date)

📋 setFullYear() vs Similar Methods

Pick the setter that matches the calendar field and timezone you need.

setFullYear()
local yr

Four-digit year

getFullYear()
read

Getter pair

setUTCFullYear()
UTC yr

UTC setter

setMonth()
month

Month index

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Examples use new Date(year, monthIndex, day) for predictable local dates.

📚 Getting Started

Change only the year while keeping month and day.

Example 1 — Set the Year to 2027

Start on Feb 26, 2026 and move to Feb 26, 2027.

JavaScript
const date = new Date(2026, 1, 26); // Feb 26, 2026
date.setFullYear(2027);

console.log(date.getFullYear()); // 2027
console.log(date.getMonth());    // 1 (February)
console.log(date.getDate());     // 26
Try It Yourself

How It Works

Only the year changes when you pass a single argument. Month index and day stay the same on valid calendar dates.

📈 Practical Patterns

Full date overload, increments, return values, and leap-year edge cases.

Example 2 — Set Year, Month, and Day Together

Use the three-argument overload for a complete calendar date in one call.

JavaScript
const date = new Date(2026, 1, 26);
date.setFullYear(2027, 6, 15); // July 15, 2027

console.log(date.getFullYear()); // 2027
console.log(date.getMonth());    // 6 (July)
console.log(date.getDate());     // 15
Try It Yourself

How It Works

Month is zero-based: index 6 is July. This overload is handy for form submissions that pick year, month, and day separately.

Example 3 — Add One Year with setFullYear(getFullYear() + 1)

Annual renewals and subscription extensions often use this pattern.

JavaScript
const renewal = new Date(2026, 2, 15); // March 15, 2026
renewal.setFullYear(renewal.getFullYear() + 1);

console.log(renewal.getFullYear()); // 2027
console.log(renewal.getMonth());      // 2 (March)
console.log(renewal.getDate());       // 15
Try It Yourself

How It Works

Read the current year, add one, write it back. Watch leap-day dates—Feb 29 plus one year normalizes in non-leap years.

Example 4 — Use the Return Value (Epoch Milliseconds)

setFullYear returns the updated timestamp—not the Date for chaining.

JavaScript
const date = new Date(2026, 1, 26);
const ms = date.setFullYear(2027);

console.log("Returned ms:", typeof ms);           // "number"
console.log("Matches getTime():", ms === date.getTime()); // true

// Correct multi-step updates on the same Date:
date.setFullYear(2028);
date.setMonth(11);
date.setDate(31);
Try It Yourself

How It Works

Do not write date.setFullYear(2027).setMonth(11)—the first call returns a number, not a Date. Call each setter on date separately.

Example 5 — Leap-Day Normalization (Feb 29 → Non-Leap Year)

Moving Feb 29, 2024 to 2025 rolls into March because 2025 is not a leap year.

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

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

How It Works

There is no Feb 29 in 2025, so the engine normalizes to March 1. Plan birthday and anniversary logic accordingly.

🚀 Common Use Cases

  • Subscription renewals — bump expiry by one year.
  • Date pickers — apply user-selected year to an existing Date.
  • Fiscal year rollovers — set year while keeping month/day anchors.
  • Form assembly — combine year, month, day with the three-arg overload.
  • Historical dates — set years before 1000 or after 9999 (four-digit API).
  • Clone + mutate — copy a Date before changing the year for comparisons.

🧠 How setFullYear() Updates the Calendar Year

1

Read local parts

Engine loads current local year, month, and day.

Local
2

Apply new year

Year argument replaces the year; optional month/day override too.

setFullYear
3

Normalize

Invalid combos (e.g. Feb 29 in non-leap) roll forward.

Normalize
4

Mutate & return ms

Date updates in place; epoch milliseconds are returned.

📝 Notes

  • setFullYear() mutates the original Date—clone if you need the old value.
  • Month argument is zero-based (January = 0), same as getMonth().
  • Returns epoch ms, not the Date—no fluent chaining on the return value.
  • Feb 29 in non-leap years normalizes to March 1 (or similar overflow).
  • Use setUTCFullYear when rules follow UTC, not local time.
  • Validate with Number.isNaN(date.getTime()) before calling setters on parsed dates.

Browser & Runtime Support

Date.prototype.setFullYear() has been available since ES1. It works in every browser and Node.js.

Baseline · ES1

Date.prototype.setFullYear()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer, and all Node.js versions. No polyfill required.

99% Universal API
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. Remember the optional month/day overload and that the return value is a number.

Conclusion

setFullYear() writes the four-digit local year on a JavaScript Date, with an optional month-and-day overload. Use it for renewals and calendar edits; clone first when preserving the original instant.

Next, learn setMonth() to change the month index, or review getFullYear() for reading the year component.

💡 Best Practices

✅ Do

  • Use the three-arg form when setting year, month, and day together
  • Clone with new Date(d) before mutating shared dates
  • Call setters sequentially on the same Date variable
  • Handle Feb 29 anniversaries explicitly in business logic
  • Pair with getFullYear() for increment patterns

❌ Don’t

  • Chain .setMonth() on the numeric return value
  • Assume month args are 1–12 (they are 0–11)
  • Mix local setters with UTC getters in one label
  • Forget leap-day normalization on +1 year logic
  • Use deprecated setYear() instead of setFullYear()

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.setFullYear()

Your foundation for local year writes in JavaScript.

5
Core concepts
📈 02

Overload

y, m, d.

Args
03

+ 1 yr

getFullYear.

Pattern
🔄 04

Mutates

In place.

Behavior
📅 05

Feb 29

Normalizes.

Edge

❓ Frequently Asked Questions

It sets the four-digit year of a Date object in local time. The Date is mutated in place and the method returns the updated epoch milliseconds.
Yes. setFullYear(year, monthIndex, day) accepts optional month (0–11) and day (1–31) arguments to update all three calendar fields in one call.
getFullYear() reads the current 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 setFullYear(2025) without changing month/day.
No. It returns a number (epoch milliseconds)—the same as getTime() after the change. Do not chain .setMonth() directly on the return value.
setFullYear() changes the local calendar year. setUTCFullYear() changes the UTC calendar year. Use the one that matches your timezone rules.
Did you know?

setFullYear(2027, 6, 15) sets July 15, 2027 in one call—month index 6 is July, not June, because JavaScript months are zero-based like getMonth().

Continue to setMonth()

Learn how to set the zero-based month index (0–11) on a Date object.

setMonth() 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.

6 people found this page helpful