This is just a short reminder post to not use the getYear method on the Date object in JavaScript. In case you weren’t aware, or like me had forgotten, getYear is not Y2K compliant and only returns a year relative to 1900 in FireFox.

So, for instance, if you were write the following:

var today = new Date;

You would end up seeing an alert box that showed 107 if you ran the script in FireFox. Interestingly enough in IE you would see 2007. I don’t know who is following the standard, and frankly I don’t care. Instead I just want to do it right and in this case you do so by using getFullYear which returns a 4 digit year value.

var today = new Date;

This will return 2007 in IE, Firefox, and Opera.


Bill Schneider

Interesting consequence - if you use getYear()/setYear() to set a cookie expiration date in the past, it won’t matter to Firefox, since 108 (as opposed to 2008) is still in the past. Chrome is a little stricter.

Zach Gardner

Firefox’s implementation of getYear() is consistent with the ECMAScript definition for the function. It is IE that isn’t standards complaint. return-108


Thanks! Your post solved an issue I was having with some JavaScript that I wrote.


Thanks for the solution.