How to Automatically Display the Date on Websites

Helpful tip #33

Here is how to code your site to display the current date.

There are a some different ways to place an autodate script in your website code, with javascript or php coding.

You can use a few lines of JavaScript which picks up the date information from the visitor’s computer and displays it on the web page. Here’s the full javascript version if you want to copy it:

<script language=”JavaScript”<!–
var days=new Array(8);
days[1] = “Sun”;
days[2] = “Mon”;
days[3] = “Tue”;
days[4] = “Wed”;
days[5] = “Thu”;
days[6] = “Fri”;
days[7] = “Sat”;
var months=new Array(13);
months[1] = “Jan”;
months[2] = “Feb”;
months[3] = “Mar”;
months[4] = “Apr”;
months[5] = “May”;
months[6] = “Jun”;
months[7] = “Jul”;
months[8]= “Aug”;
months[9] = “Sep”;
months[10] = “Oct”;
months[11] = “Nov”;
months[12] = “Dec”;
var dateObj=new Date()
var wday=days[dateObj.getDay() + 1]
var lmonth=months[dateObj.getMonth() + 1]
var date=dateObj.getDate()
var year=dateObj.getYear()
if (year >= 100 && year <= 1999)
{year=year + 1900}
document.write(wday + “, ” + date+ ” ” + lmonth + ” ” + year)
// –>

If you want to put in the full word for “Mon” or “Jan”, you just need to change the wording in the script. Just place this script in where the ‘date’ would normally show up.

That is all about this secret. I hope it helps and works for your sites.