INFO: Date.getYear() Method Return Value Changed (183618)



The information in this article applies to:

  • Microsoft JScript 1.0
  • Microsoft JScript 2.0
  • Microsoft JScript 3.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.0

This article was previously published under Q183618

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, see the following ECMA Web site:

For information on using JScript, see the documentation that is available at the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:3/16/2005
Keywords:kbinfo KB183618