Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2002, 05:26 AM   PM User | #1
Deanna475
Regular Coder

 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Deanna475 is an unknown quantity at this point
Question Need date script that works in NS

I'm preparing my online resume and have run into a glitch. I want to include the date only -- not the time -- on my cover letter page but every date JavaScript I've tried buggers up in NS 4.7 (don't know about NS 6 as I don't have it installed). While the date shows up perfectly in IE, the year always gets jumbled in NS. For example:

Saturday, July 6, 102

or

Saturday, July 6, 19102

Does anyone have a date only script that works in NS? Any help would be greatly appreciated. I can hardly expect to get the job if I can't get the date right on the first page!
Deanna475 is offline   Reply With Quote
Old 07-07-2002, 05:39 AM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
basically,,,,netscape looks at the date a different way

one way to do it is this

if(Year<2000){Year+=1900;}
A1ien51 is offline   Reply With Quote
Old 07-07-2002, 06:27 AM   PM User | #3
Deanna475
Regular Coder

 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Deanna475 is an unknown quantity at this point
Hi A1ien51 and thanks for the quick response. Your solution seems simple, but NS still doesn't like it. This is the most simple script I was trying and it would seem to fit perfectly with your solution:

<SCRIPT type="text/javascript" language="JavaScript1.2">
var mydate=new Date()
var year=mydate.getYear()
if (year<2000)
year="19"+year
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
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","Novem ber","December")
document.write("<font color='162040' face='Arial' size=2>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"<\/font>")
</SCRIPT

I inserted {Year+=1900;} immediately after the code in red but that doesn't do the trick in NS. The date shows up as:

Sunday, July 7, 102

BTW, you need a space between the if (Year or else you a "year not defined" error. But that's neither here nor there because with or without the space, it still doesn't work in NS.

I got this brainstorm of an idea while looking at your code and thought, "I don't need to worry about years less than 2000 since I want the current year, which is greater than 2000." So I removed this part of the script:

if (year<2000)
year="19"+year


And while it worked in IE, NS didn't like that solution either! It still showed the year as 102

Brainstorm #2: I decided to remove all references to the year and enter the year as simple text:

<SCRIPT type="text/javascript" language="JavaScript1.2">
var mydate=new Date()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
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","Novem ber","December")
document.write("<font color='162040' face='Arial' size=2>"+dayarray[day]+", "+montharray[month]+" "+daym+", 2002<\/font>")
</SCRIPT>

And this worked in IE, but NS didn't like that solution either! It still showed the year as 102

<sigh> It's a simple little date code. How can NS bugger up something so simple? (rhetorical question -- I know why!) I would say to heck with the date appearing correctly in NS but it would be my luck that the employer who wants to hire me is using NS !!!!
Deanna475 is offline   Reply With Quote
Old 07-07-2002, 02:24 PM   PM User | #4
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
Here is the code you need


<SCRIPT type="text/javascript" language="JavaScript1.2">
var mydate=new Date()
var year=mydate.getYear()
if(year<2000){year+=1900;}
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
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","Novem ber","December")
document.write("<font color='162040' face='Arial' size=2>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"<\/font>")
</SCRIPT>
A1ien51 is offline   Reply With Quote
Old 07-07-2002, 08:11 PM   PM User | #5
Deanna475
Regular Coder

 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 104
Thanks: 0
Thanked 0 Times in 0 Posts
Deanna475 is an unknown quantity at this point
Yep, that does the trick! The difference one line of code makes! Thank you very much.
Deanna475 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:34 PM.


Advertisement
Log in to turn off these ads.