Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Can Server-Side Includes (SSI) Produce Date or Time Output?

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?"

Dave's Answer: 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: Friday, 04-Jul-2008 14:25:42 MDT

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: 2008 . 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!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments
Rather amazingly, there are no comments on this article yet.

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Uniblue: Free Virus Scan

Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]