The question arose: “I’m always forgetting to change the copyright notices on the bottom of my Web pages, so it’s not uncommon for me to have 2003 as the copyright well into 2004, and I’m sure that I’ll do the same thing in 2005. Help! Surely there’s some easy SSI trick for fixing this?”
Now this is the kind of question that applies to my own sites too, so it’s one I’m particularly interested in researching. It turns out that not only can the server-side include capability of Apache web servers (and other Web servers that offer SSI capabilities) give you an easy way to include other files or HTML snippets (as I do on this very page!), but it offers a lot more capability too.
I talk about some of these capabilities in my book Creating Cool Web Sites with HTML, XHTML and CSS, but rather than do that annoying Time-Life ad bit of “buy the book!” I’ll just answer the question, okay? 🙂
There’s a helpful directive in SSI called echo which can produce the date and time on your page without any JavaScript and without any CGI programming. It’d look like this:
<!--#echo var="DATE_LOCAL" -->
Mildly interesting, right? Here’s what happens on this page when the directive is expanded:
If you use the config option beforehand, you can actually create any timestring you want exactly as you can pass date and time format strings as an argument in Unix’s date command! So here’s the answer to your question:
<!--#config timefmt="%Y" --> <!--#echo var="DATE_LOCAL" -->
And here’s its output:
. Cool stuff, eh? You can easily imagine an always up-to-date copyright notice now, can’t you?
There are a number of different references online that give much more detail about the timefmt string, but here’s the one I’ve found the clearest: Indiana University’s Webmaster SSI Tutorial.
Oh! If you’re using PHP, don’t forget that you can accomplish the same trick by using:
<?echo date('Y');?>
Hope that helps you out!