Microsoft KB Archive/183618

= INFO: Date.getYear Method Return Value Changed =

Article ID: 183618

Article Last Modified on 8/8/2007

-

APPLIES TO


 * Microsoft JScript 1.0
 * Microsoft JScript 2.0
 * Microsoft JScript 3.0
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.0 128-Bit Edition

-



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.

