Need some help dynamically setting day/date

K

Keith

I don't know javascript and was wondering if someone might give me a simple
script to dynamically display the day and date in the following format:

Sunday, October 12, 2003

Any help would be appreciated -- thanks. I'll give you credit for the script
in the comments if you want.
 
I

Ivo

Keith said:
I don't know javascript and was wondering if someone might give me a simple
script to dynamically display the day and date in the following format:

Sunday, October 12, 2003

Any help would be appreciated -- thanks. I'll give you credit for the script
in the comments if you want.

This bit of code will put the current date at the location within the body
where you choose to put this script:

<script type="text/javascript"><!--
var mydate=new Date();
var year=mydate.getFullYear();if (!year) year=mydate.getYear()+2000;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
var dayarray=new Array("Sun","Mon","Tues","Wednes","Thurs","Fri","Satur")
var montharray=new
Array("January","February","March","April","May","June","July","August","Sep
tember","October","November","December")
window.status=dayarray[day]+"day, "+daym+" "+montharray[month]+", "+year;
// --></script>
 
T

The Keith

thanks but I just found this one--works fine:
http://www.jwweb.com/20010325.html



Ivo said:
Keith said:
I don't know javascript and was wondering if someone might give me a simple
script to dynamically display the day and date in the following format:

Sunday, October 12, 2003

Any help would be appreciated -- thanks. I'll give you credit for the script
in the comments if you want.

This bit of code will put the current date at the location within the body
where you choose to put this script:

<script type="text/javascript"><!--
var mydate=new Date();
var year=mydate.getFullYear();if (!year) year=mydate.getYear()+2000;
var day=mydate.getDay();
var month=mydate.getMonth();
var daym=mydate.getDate();
var dayarray=new Array("Sun","Mon","Tues","Wednes","Thurs","Fri","Satur")
var montharray=new
Array("January","February","March","April","May","June","July","August","Sep
tember","October","November","December")
window.status=dayarray[day]+"day, "+daym+" "+montharray[month]+", "+year;
// --></script>
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
var year=mydate.getFullYear();if (!year) year=mydate.getYear()+2000;

There is no point in coding for the attempted use of a possibly-present
method if you are going to provide code for an alternative always-
available method anyway - the user has to download both, and you need to
test both.

In fact, AIUI, getFullYear is JS 1.2, which was implemented in version 4
of two major browsers, and so is probably safe enough.

If I simulate the absence of getFullYear by mis-spelling it, I get an
error message, that year is undefined.

If I omit that statement, the if part results in an error message, that
year is undefined.

If I do just year=mydate.getYear()+2000; I get 4003; getYear()
gave 2003. It may be that, wherever getFullYear does not exist,
getYear() gives Year%100; but I rather doubt it and expect it to give
Year-1900.

I believe year = mydate.getYear()%1900 + 1900 to be safe until
end 3799, but unnecessary; and year = mydate.getYear()%100 + 2000
to be OK until end 2099. Read the FAQ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top