SSI: Dates and Times
[The timefmt Argument]
This is the second in a series of three tutorials on SSIs (Server Side Includes). These are commands from the PERL language that allow you to include files and information right from the server.
If you haven't already, please take the time to read the original SSI tutorial first.
In that tutorial you'll get a little script that allows you to test your server to see if you're even able to play with these commands, and a lesson on the "include" command. It's best that you do read that first because I'm going to assume you have at this point and just bull forward.
Config and EchoLet's talk about the basic format first. Once we have that, then the rest is a simple chart of what argument returns what. Here's the format:
The format for these includes is quite rigid. You must keep it the same. Do not put in spaces where they don't now appear. HTML is flexible. This is not. The biggest mistake I make is not having a space just before the final two dashes at the end of the command lines. Make sure that's in there. You don't get error warnings with these commands. They simply fail to work and you can spend hours trying to figure out what's wrong when it's only a missing space.
I guess the point I'm making is to not mess with the layout of the command line.
That said, look at what we have here. It's actually two command lines, one after the other. The first command line denotes the time format and the second echoes it back. See that?
Let me start with the second one because that's the one that requires the least amount of work. In fact, it requires no work. Leave it the way it is. The echo command should always have the var argument set to "DATE_LOCAL", in caps, with an underscore between the words.
Every time you set an include to grab a date or a time, always follow that command with this echo command line so it echoes back and gets posted to the page.
I think I've driven that point into the ground.
The timefmt ArgumentMoving backward, we get to the first command line. That's the one that reads #config timefmt="--".
The leading hash mark (#) is required, keep it. The argument "timefmt=" is used every time you want to return a date or time. The big question is what you want returned. There are 21 choices, each identified by a percent mark, a one-letter code that goes in between the quotes following "timefmt=".
The CodesThe codes make little sense to me. They don't seem to represent what they return, so you'll need some kind of chart to keep it all straight. I have one below.
I'll use the first code, %a, to demonstrate a command line. The code %a will return the abbreviated weekday name (Mon, Tue, Wed) depending on the current local. The command would look like this:
...and here's what it gives you:
There's no need looking at the source code to see how I placed the command lines because they won't be there. Only the return provided by the server will display.
Here are all 21 timefmt arguments, what you'll get, and an example.
|Argument||You Get:||It Looks Like:|
|%a||Abbreviated Weekday Name|
|%A||Full Weekday Name|
|%b||Abbreviated Month Name|
|%B||Full Month Name|
|%c||Preferred Date & Time|
|%d||Day of Month as digit|
|%H||Hour Number (24-Hour Clock)|
|%I||Hour Number (12-Hour Clock)|
|%j||Day of the Year Number|
|%m||Month as digit|
|%p||AM or PM|
|%U||Week Number/Sunday as Day One|
|%w||Day of the Week Number|
|%x||Preferred Format without Time|
|%X||Preferred Format without Date|
|%y||Two-Digit Year Number|
You might notice that some of the elements claim they represent the "preferred" format; "preferred" means the default settings of the server. It can differ from server to server.
Notice also that these returns are from the server. If you are in one time zone and the server is in another, the time zone the server is in will be reflected in the returned values.
Multiple CodesThe codes above can be used one right after another to create a longer date/time stamp. Let's say you want something that looks like this:
You could set up an SSI that looks like this:
See how one just followed the other? The commas are in there, too. You can make up any combination you want by just following one with the other, leaving spaces and putting commas where you want them. Very cool.
That's ThatThese are great includes. My school Webmaster uses them to death. Hopefully, you too can find a use for them.
[The timefmt Argument]
IT Solutions Builder TOP IT RESOURCES TO MOVE YOUR BUSINESS FORWARD
Which topic are you interested in?
What is your company size?
What is your job title?
What is your job function?
Searching our resource database to find your matches...