Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

How do you get a dynamic date?

Help please

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

Preferred Member

10+ Year Member

joined:May 15, 2002
posts:542
votes: 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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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]

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

Senior Member

joined:Jan 27, 2003
posts:2534
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2001
posts:2488
votes: 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>

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

Preferred Member

10+ Year Member

joined:May 15, 2002
posts:542
votes: 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!

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

Senior Member

joined:Jan 27, 2003
posts:2534
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 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

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

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


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

[webmasterworld.com...]

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 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.
12:26 am on Feb 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Some of the solutions in the above thread are server side IIRC.
12:41 am on Feb 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 17, 2002
posts:2251
votes: 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. :)
12:50 am on Feb 23, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 22, 2002
posts:1782
votes: 0


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

Andreas