471,075 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

Need some help dynamically setting day/date

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.
Jul 20 '05 #1
3 2115
Ivo

"Keith" <no@spam.com> wrote in message
news:ZG**********************@twister.nyc.rr.com.. .
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","S atur")
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>
Jul 20 '05 #2
thanks but I just found this one--works fine:
http://www.jwweb.com/20010325.html

"Ivo" <no@thank.you> wrote in message
news:3f*********************@news.wanadoo.nl...

"Keith" <no@spam.com> wrote in message
news:ZG**********************@twister.nyc.rr.com.. .
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","S atur")
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>

Jul 20 '05 #3
JRS: In article <3f*********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Sun, 12 Oct 2003
21:40:14 :-
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.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James Hong | last post: by
3 posts views Thread by NewmanBT | last post: by
2 posts views Thread by Duncan Welch | last post: by
8 posts views Thread by Elliot M. Rodriguez | last post: by
4 posts views Thread by Bob | last post: by
3 posts views Thread by Fetty | last post: by
13 posts views Thread by vgame64 | last post: by

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.