473,465 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Different in IE and Firefox: now.getYear()+1900

I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:

Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);

In IE, I get 9/28/3907.

I could not find specific reference to this in the FAQs and

http://www.merlyn.demon.co.uk/js-dates.htm

Do I need to detect the browser and compensate accordingly?

My application is posted at: www.smart.net/~pstech/DogLicenseJS.htm

Thanks,

Paul
Sep 28 '07 #1
8 10043
Paul E. Schoen wrote:
I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:

Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);
Why not use now.getFullYear() ? It takes away any doubts about what
you're getting.
Sep 28 '07 #2
Paul E. Schoen said the following on 9/28/2007 4:24 AM:
I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:

Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);

In IE, I get 9/28/3907.

I could not find specific reference to this in the FAQs and

http://www.merlyn.demon.co.uk/js-dates.htm

Do I need to detect the browser and compensate accordingly?
No, don't detect a browser. Use getFullYear instead and forget about
having to add 1900 at all.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '07 #3

"Randy Webb" <Hi************@aol.comwrote in message
news:eb*********************@giganews.com...
Paul E. Schoen said the following on 9/28/2007 4:24 AM:
>I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:

Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);

In IE, I get 9/28/3907.

I could not find specific reference to this in the FAQs and

http://www.merlyn.demon.co.uk/js-dates.htm

Do I need to detect the browser and compensate accordingly?

No, don't detect a browser. Use getFullYear instead and forget about
having to add 1900 at all.
Thanks. That worked well. My old Javascript reference book does not have
that function listed, but it specifies the getYear() function as years
since 1900. Why is it wrong in IE? Or is that a silly question?

Paul
Sep 28 '07 #4
Paul E. Schoen said the following on 9/28/2007 4:23 PM:
"Randy Webb" <Hi************@aol.comwrote in message
news:eb*********************@giganews.com...
>Paul E. Schoen said the following on 9/28/2007 4:24 AM:
>>I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:

Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);

In IE, I get 9/28/3907.

I could not find specific reference to this in the FAQs and

http://www.merlyn.demon.co.uk/js-dates.htm

Do I need to detect the browser and compensate accordingly?
No, don't detect a browser. Use getFullYear instead and forget about
having to add 1900 at all.

Thanks. That worked well. My old Javascript reference book does not have
that function listed, but it specifies the getYear() function as years
since 1900. Why is it wrong in IE? Or is that a silly question?
Because there is nothing that says whether IE is wrong or FF. An
argument could be made that FF is getting it wrong since getYear could
be (and for 30 years or so) was a 2 digit year. Rather than update
getYear for Y2K, MS left alone and FF changed it to retrieve a 4 digit
year. Both implements getFullYear which specifies that it returns the 4
digit year number.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Sep 28 '07 #5
In comp.lang.javascript message <46***********************@news.coretel.
net>, Fri, 28 Sep 2007 04:24:30, Paul E. Schoen <ps****@smart.netposted:
>
Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);

In IE, I get 9/28/3907.

I could not find specific reference to this in the FAQs and

http://www.merlyn.demon.co.uk/js-dates.htm
Anchor http://www.merlyn.demon.co.uk/js-date0.htm#gY is linked from
getYear in the index part of http://www.merlyn.demon.co.uk/js-dates.htm ;
but start at #Y2k, and read at least enough.

I've just added a green box. Can anyone identify any systems for which
getYear returns year mod 100 ?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 28 '07 #6
On Sep 29, 6:23 am, "Paul E. Schoen" <pst...@smart.netwrote:
"Randy Webb" <HikksNotAtH...@aol.comwrote in message

news:eb*********************@giganews.com...
Paul E. Schoen said the following on 9/28/2007 4:24 AM:
I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:
Form1.ApplicationDate.value = (now.getMonth()+1) + "/" + now.getDate() +
"/" + (now.getYear()+1900);
In IE, I get 9/28/3907.
I could not find specific reference to this in the FAQs and
>http://www.merlyn.demon.co.uk/js-dates.htm
Do I need to detect the browser and compensate accordingly?
No, don't detect a browser. Use getFullYear instead and forget about
having to add 1900 at all.

Thanks. That worked well. My old Javascript reference book does not have
that function listed, but it specifies the getYear() function as years
since 1900. Why is it wrong in IE? Or is that a silly question?
Because MS decided that IE would implement a non-standard version of
getYear:

<URL: http://msdn2.microsoft.com/en-us/library/x0a9sc10.aspx >

Don't bother with books when better resources are available online,
the MS JScript reference is here:

<URL: http://msdn2.microsoft.com/en-us/library/hbxc2t98.aspx >

And their DOM (DHTML) reference is here:

<URL: http://msdn2.microsoft.com/en-us/library/ms533050.aspx >

I'll presume you know where to find the W3C and other references.

--
Rob

Sep 29 '07 #7

"RobG" <rg***@iinet.net.auwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
On Sep 29, 6:23 am, "Paul E. Schoen" <pst...@smart.netwrote:
>"Randy Webb" <HikksNotAtH...@aol.comwrote in message

news:eb*********************@giganews.com...
Paul E. Schoen said the following on 9/28/2007 4:24 AM:
I just noticed that my javascript app gives the wrong year in IE, but
correct in Firefox, when I use:
>Form1.ApplicationDate.value = (now.getMonth()+1) + "/" +
now.getDate() +
"/" + (now.getYear()+1900);
>In IE, I get 9/28/3907.
>I could not find specific reference to this in the FAQs and
>>http://www.merlyn.demon.co.uk/js-dates.htm
>Do I need to detect the browser and compensate accordingly?
No, don't detect a browser. Use getFullYear instead and forget about
having to add 1900 at all.

Thanks. That worked well. My old Javascript reference book does not have
that function listed, but it specifies the getYear() function as years
since 1900. Why is it wrong in IE? Or is that a silly question?

Because MS decided that IE would implement a non-standard version of
getYear:

<URL: http://msdn2.microsoft.com/en-us/library/x0a9sc10.aspx >

Don't bother with books when better resources are available online,
the MS JScript reference is here:

<URL: http://msdn2.microsoft.com/en-us/library/hbxc2t98.aspx >

And their DOM (DHTML) reference is here:

<URL: http://msdn2.microsoft.com/en-us/library/ms533050.aspx >

I'll presume you know where to find the W3C and other references.
It is even more frustrating that the original version 1.0 worked
"properly", and then for some reason they broke it, and made it obsolete:

"For JScript version 1.0, getYear returns a value that is the result of the
subtraction of 1900 from the year value in the provided Date object,
regardless of the value of the year. For example, the year 1899 is returned
as -1 and the year 2000 is returned as 100."

My book "Using JScript" by Mark Reynolds was Copyright 1997 (and the CD was
1996), so that was just before the Y2K craziness. But it seems that they
broke the getYear() function in the worst possible way:

"For the years 1900 though 1999, the year is a 2-digit integer value
returned as the difference between the stored year and 1900. For dates
outside that period, the 4-digit year is returned. For example, 1996 is
returned as 96, but 1825 and 2025 are returned as-is."

It was supposed to return a 2-digit integer, but it became 3-digit in 2000.
If it were truly modulus 100, it would have been OK for the popular
two-digit year, but would give wrong results if the +1900 were used. But
the way it was worked fine in most cases. Making a special case of years
from 1900-1999 rendered the function useless, as there was no simple way to
determine if the date were within that range, and adjust accordingly. It
seems like a lesson in "if it ain't broke, don't fix it", and they broke it
by attempting a clumsy fix. Then they had to declare a new function and
make the original obsolete.

I hope there aren't too many stupid differences among the various popular
browsers. It appears that the FAQ and the merlyn pages cover these pretty
well, so I guess I'll just have to read up on other functions I might use.

Thanks for all the helpful discussion.

Paul
Sep 29 '07 #8
In comp.lang.javascript message <11*********************@57g2000hsv.goog
legroups.com>, Fri, 28 Sep 2007 22:26:23, RobG <rg***@iinet.net.au>
posted:
>On Sep 29, 6:23 am, "Paul E. Schoen" <pst...@smart.netwrote:
>Thanks. That worked well. My old Javascript reference book does not have
that function listed, but it specifies the getYear() function as years
since 1900. Why is it wrong in IE? Or is that a silly question?

Because MS decided that IE would implement a non-standard version of
getYear:
But did a formal standard exist when Microsoft implemented getYear?

It's just the local habit of doing what seems most attractive at the
time, without regard for the consequences.

It was probably felt, earlier, that getting the full year and using mod
100 would be too difficult for the average local.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Sep 29 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
3
by: David Hayes | last post by:
I've made tooltips work in Firefox*, but tooltip doesn't appear at the specified location until the SECOND time that the user passes the mouse over the location with the mouseover event. What I...
8
by: Lian | last post by:
Hi all, It is a newbie's question about html tag "img". The attributes "title" and "alt" for "img" seems having the same function. So what is the main difference between them? Can i use them at...
11
by: Robert | last post by:
Hi, My previous thread on this topic was too short on information so I I'll try again. When I tried out Firefox 1.5 beta some of my javascript did not work anymore. Here is some code to...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
13
by: Giggle Girl | last post by:
Hi there, I am having a problem with the behavior of Firefox, where lefthand column content is not resized properly after it is "collapsed" and then "re-expanded". An online demo is available...
7
by: Xah Lee | last post by:
Look at this page http://xahlee.org/emacs/wrap-url.html Look at it in Firebox, look at it in Safari, in Opera, and look at it in Microsoft Internet Explorer. The only fucked up case, is...
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.