Forum Moderators: mack

Message Too Old, No Replies

How do you get a dynamic date?

Help please

         

dazz

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

10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

10+ Year Member



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

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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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

[webmasterworld.com...]

GaryK

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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

GaryK

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

Andreas