VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-date-setfullyear-method/

⇱ JavaScript Date setFullYear() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

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:

  • year_Value: This parameter holds the value of year which is used to set in the Date() constructor.

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: 

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. 

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. 

Output:

2007
2
30

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Mozilla Firefox
  • Opera
  • Safari

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

Comment