Click to See Complete Forum and Search --> : Wrong year displayed in IE 6


bryce4president
02-07-2008, 03:31 PM
I have a date script but it displays the wrong year in IE6. In FF2 it says 2008, but in IE6 it says 3908...

function getDate() {
var mydate=new Date();
var year=mydate.getYear();
if (year < 1000);
year+=1900;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
if (daym<10)
daym="0"+daym;
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = dayarray[day]+", "+montharray[month]+" "+daym+", "+year;
return date;
}

Any clues?

magentaplacenta
02-07-2008, 03:57 PM
Date.getyear() is deprecated, use Date.getFullYear() instead.

You had a problem with your conditional.

if (year < 1000);
year+=1900;

Should be (note removal of ; on if line):

if (year < 1000) year+=1900;

But with getFullYear(), you don't have to bother with that.

function getDate() {
var mydate=new Date();
var year=mydate.getFullYear();
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
if (daym<10)
daym="0"+daym;
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var date = dayarray[day]+", "+montharray[month]+" "+daym+", "+year;
alert(date);
}

bryce4president
02-07-2008, 04:03 PM
Thanks...I didn't realize it was deprecated.

JMRKER
02-07-2008, 04:20 PM
Regardless of the deprecated status, the check should have been:

You had a problem with your conditional.

if (year < 100) { year+=1900; }


FullYear() is still the better way to go.

bryce4president
02-08-2008, 07:28 AM
Yeah, I went with FullYear(). Why mess with something that isn't needed. It just takes up space :)

felgall
02-08-2008, 02:08 PM
All references to getYear() were supposed to be replaced with getFullYear() during the Y2K conversions done back in 1999 and earlier. By the end of 1999 all references to getyear() should have been removed.

bryce4president
02-08-2008, 02:13 PM
Well I wasn't programming JavaScript until just last year. And I got this from someone here at work. I know, I know, that's what I get for just using someone else's stuff...trust no one's code even if it written by the guy sitting next to you. And I got that script down to below 425 bytes. Think I should zip it too?

bryce4president
02-08-2008, 02:33 PM
Hey felgall,

I got curious and visited your website. You've got an error in your head.js script. My firebug went bonkers over it. every time I scroll up or down it gives an error. You might want to check it out... any way you can email me about your rating system stuff as well? I have some concerns about it...