INFO: Date.getYear() Method Return Value Changed

ID: Q183618


The information in this article applies to:


SUMMARY

In JScript 3.0, the Date.getYear() method returns the full year for years after 1999.


MORE INFORMATION

In JScript 1.0, which is installed with Microsoft Internet Explorer 3.0, the Date.getYear() method returns the current year minus 1900. So, the year 1999 returns 99 and the year 2000 returns 100.

In JScript 3.0, which is installed with Microsoft Internet Explorer 4.0, the Date.getYear() method returns a two-digit value for years after 1900 and prior to 2000 and a four-digit value for years after 1999. So, the year 1999 returns 99 and the year 2000 returns 2000.

The following JScript demonstrates this behavior:


var d = new Date(2000, 1, 16)
   alert("Date: " + d.getYear()); // returns 2000 in JScript 3.0
                                  // returns 100 in JScript 1.0 
This change was made to conform to ECMA 262, the standard on which JScript is based.

If you always require a four-digit year value, use the Date.getFullYear() method.

The following script demonstrates how to implement your own getFullYear() function that works in browsers that implement non-ECMA JavaScript:

   function getFullYear(date)
   {
      fullyear = date.getYear();
      if (fullyear < 1000) fullyear = fullyear + 1900;
      return fullyear;
   } 
The above script works for all years after 1000.


REFERENCES

For more information on the ECMA standard, refer to the following Web site:

http://www.ecma.ch/stand/ecma-262.htm
For information on using JScript, refer to the documentation available at the following Web site:
http://msdn.microsoft.com/scripting/

Additional query words:


Keywords          : kb2000 
Version           : WINDOWS:1.0,2.0,3.0,4.0,4.01
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: July 14, 1999