homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
How do you get a dynamic date?
Help please
dazz




msg:971952
 2:51 pm on Feb 21, 2003 (gmt 0)

I have a form with dates on. How can I get the dates to change to keep up with the current date?

At the moment I just change it manually every month but its getting abit boring now!

Thanks

 

andreasfriedrich




msg:971953
 2:57 pm on Feb 21, 2003 (gmt 0)

If the site is hosted on an Apache [httpd.apache.org] server you could use mod_include [httpd.apache.org].

<!--#echo var="DATE_LOCAL" -->

The above code will insert the local date.

Of course you could use any server side scripting language as well.

Andreas

[edited by: andreasfriedrich at 2:58 pm (utc) on Feb. 21, 2003]

Receptional Andy




msg:971954
 2:58 pm on Feb 21, 2003 (gmt 0)

You can use javascript to automatically display the current date (for the visitor). Use the following code to display the date in a simple format.

<script language="JavaScript" type="text/javascript">
<!--
var date = new Date();
var d = date.getDate();
var day = (d < 10)? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10)? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000)? yy + 1900 : yy;
document.write(day + "/" + month + "/" + year);
//--></script>

A search of Google for javascript date scripts ( [google.com...] )will return many other useful scripts that will format the output to your requirements.

caine




msg:971955
 3:11 pm on Feb 21, 2003 (gmt 0)

this is a useful one also.

<SCRIPT LANGUAGE="JavaScript1.2">
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<right>" + lmonth + " ");
document.write(date + ", " + year + "</right>");
</script>

dazz




msg:971956
 3:27 pm on Feb 21, 2003 (gmt 0)

Thanks for that, it is great help but unfortunately I dont know where to put the scripts!

Ive tried them both a few places and I usually get script error or the date just doesnt change!

Receptional Andy




msg:971957
 3:33 pm on Feb 21, 2003 (gmt 0)

Put the scripts wherever you were normally putting the date on your page. When copying and pasting, make sure you don't alter anything in the scripts above.

The only important thing really is that the script is between the <body> tags of your page. If you are using a WYSIWYG editor like Frontpage you will need to look at the source code.

If this doesn't make sense, sticky me or post and I will talk you through it.

andreasfriedrich




msg:971958
 3:42 pm on Feb 21, 2003 (gmt 0)

BTW if the date is vital to your form Iīd go with a server side solution.

The JavaScript would go into a script element somewhere on your html document or an external file that you reference using the src attribute of the script elementīs start tag.

Andreas

g1smd




msg:971959
 9:13 pm on Feb 22, 2003 (gmt 0)

I'm going to point you back to this long thread, as there was some code examples included there:

[webmasterworld.com...]

GaryK




msg:971960
 9:26 pm on Feb 22, 2003 (gmt 0)

Please keep in mind that more and more people seem to be surfing with JavaScript disabled because of security issues. People like myself will see nothing where your date should be. A server-side solution is really your best bet for maximum compatibility.

g1smd




msg:971961
 12:26 am on Feb 23, 2003 (gmt 0)

Some of the solutions in the above thread are server side IIRC.

GaryK




msg:971962
 12:41 am on Feb 23, 2003 (gmt 0)

If your comment was addressed to me. You're right some of the solutions are server-side. I never meant to imply they weren't. But since most of the suggestions seemed to involve JS I thought it would be a good idea to point out one of the downsides of JS. :)

andreasfriedrich




msg:971963
 12:50 am on Feb 23, 2003 (gmt 0)

It is a good idea GaryK, but one that does not seem to be very popular in this thread :o.

Andreas

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved