A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-date-setfullyear-method/ below:

JavaScript Date setFullYear() Method - GeeksforGeeks

JavaScript Date setFullYear() Method

Last Updated : 11 Jul, 2025

JavaScript date.setFullYear() method is used to set year into a date object which is created using Date() constructor. 

Syntax:

DateObj.setFullYear(year_Value)

Parameter: This method accepts a single parameter as mentioned above and described below:

Return Value: It returns the new date with the updated year which is set by the setFullYear() method.

Below examples illustrate the JavaScript Date setFullYear() Method:

Note: DateObj is a valid Date object created using Date() constructor in which we want to set the year. More codes for the above method are as follows:

Example 1: 

JavaScript
// Here a date has been assigned
// while creating Date object
let dateobj =
new Date('October 13, 1996 05:35:32');

// New year 1992 is being set in above Date
// Object with the help of setFullYear() method
dateobj.setFullYear(1992);

// New year from above Date Object is
// being extracted using getFullYear()
let B = dateobj.getFullYear();

// Printing new year
console.log(B);

Output:

1992

 Example 2: If in the Date() constructor we do not give any year, still setFullYear() method set a new year which is given as its parameter. 

JavaScript
// Here year has not been assigned
// while creating Date object
let dateobj =
new Date('October 13, 05:35:32');

// new year 1992 is being set in above Date
// Object with the help of setFullYear() method
dateobj.setFullYear(1992);

// New year from above Date Object is
// being extracted using getFullYear()
let B = dateobj.getFullYear();

// Printing new year
console.log(B);

Output:

1992

Example 3: If nothing as a parameter is given in the Date() constructor, still setFullYear() method set year but month and date become current ones. Here in output 2 is the month of March because the month name starts from 0 to 11 i.e, 0 for January and 11 for December, and 30 is the current date. 

JavaScript
// Here nothing has been assigned
// while creating Date object
let dateobj = new Date();

// new year 2007 is being set in above Date
// Object with the help of setFullYear() method
dateobj.setFullYear(2007);

// Year from above Date Object is
// being extracted using getFullYear()
let B = dateobj.getFullYear();

// Month from above Date Object is
// being extracted using getMonth()
let C = dateobj.getMonth();

// Date from above Date Object is
// being extracted using getDate()
let D = dateobj.getDate();

// Printing new year
console.log(B);

// Printing current month
console.log(C);

// Printing current date
console.log(D);

Output:

2007
2
30

Supported Browsers:

We have a complete list of Javascript Date Objects, to check those please go through this Javascript Date Object Complete reference article.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4