However, if you are making daily updates, you can save yourself a bit of time and effort by automatically displaying the current date as part of the page.
There are two simple ways to do this: server side includes, and PHP. Server side includes are a little bit easier, but can only display the date and time in the time zone of the web server itself, or GMT. If neither of these is correct for your purposes, read on for our PHP solution. (Similar solutions are possible with other server-side programming technologies like ASP, Cold Fusion, and so on. These two are the most universally available.)
Date and Time Stamps With Server Side IncludesThe following server side include directive will work on just about any web hosting account, with the exception of some free accounts:
The date and time will appear correct for the time zone in which the server operates. You can also output the current Greenwich Mean Time, and set the date and/or time format you wish to use. For instance, you can display the date only (without the time) by setting the date format like this:
<!--#config timefmt="$y $m $d"-->
For more information, see the excellent SSI Developer site.
Date and Time Stamps With PHPWhat if your web server is in a different time zone, and you want to display your the date and time in the time zone where you (the webmaster, not the user) are located? Unfortunately, SSI can't do it. However, PHP can. PHP, like SSI, is a way to dynamically add content to your web pages. Unlike SSI, PHP is a full-featured programming language. But taking advantage of useful snippets of PHP code doesn't require programming experience.
The following PHP code, when inserted in an HTML page that has been given a filename ending in .php (not .html), will display the current date and time in New York City:
echo date("Y-m-d h:i:sa", time());
By default, the date function of PHP also outputs the date and time for
the web server's time zone. But the putenv function changes this by setting
the effective time zone to the city we want. Linux users can find a list
of valid time zone names in the
(there are subdirectories for continents and so forth).
You can leave out the date by skipping the Y-m-d part, and you can leave out
the time by skipping the h:i:sa part. For more information about
these formatting characters and what else can be done with them, see
the PHP manual page for the
Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!