The #config Command

The #config command can be used to change the output format of certain SSI directives, specifically those which return a time / date or a filesize. This allows you to use a more understandable format than the defaults for your particular application.

The #config command takes two parameters, timefmt to modify the date and time formats, and sizefmt to modify the file size format.

The timefmt parameter takes a free form text string of tokens as an argument in a similar vein to the UNIX library call strftime. These tokens are expanded by the server to produce the desired time format.

%a Day : abbreviated Mon, Tue, Wed
%A Day Monday, Tuesday
%b Month : abbreviated (%h Jan, Feb, Mar
%B Month January, February
%C Year :Without Century "00" - "99"
%d Day of Month "01" - "31"
%D Date : mm/dd/yy "01/01/00" - "12/31/99"
%e Day of Month : Single figure "1" - "31"
%h Month : abbreviated (%b) Jan, Feb, Mar
%H Hour of Day : 24 hour clock "00" - "23"
%I Hour of Day "01" - "12"
%j Julian Day of Year "001" - "366"
%j Julian Day of Year "001" - "366"
%m Month of Year "01" - "12"
%M Minute "00" - "59"
%n Newline character  
%p AM or PM "AM" | "PM"
%r Time in %I:%M:%S %p "00:00:00 am" - "12:59:59 pm"
%R Time in %H:%M "00:00" - "23:59"
%S Seconds "00" - "61"
%T Time in %H:%M:%S "00:00:00" - "23:59:59"
%u Numbered Day of the Week : Starting with Monday = 1 "1" - "7"
%w Numbered Day of the Week : Starting with Sunday = 0 "0" - "6"
%y Year : Without Century "00" - "99"
%Y Year "0000" - "9999"
%Z Time Zone "GMT", "BST", "CST" ..
%% Percentage Character "%"

Sophisticated time and date information can be constructed using these tokens. Additional text can also be included in the string, allowing additional explanation.

The sizefmt parameter takes an argument of either bytes or abbrev. The bytes value will cause all filesize information to be displayed exactly in bytes, while the abbrev value will display an approximate value with the units appended (Kb, Mb, Gb).

Simple Example: Formatting the Date

Displaying a date on the welcome page for your site is quite a common requirement, but you probably don't want to got to all the trouble of writing a CGI script to display the whole page. You also probably don't want to use the default time format either. Using #config and the SSI environment variable date_local we can easily display the time in the way we want.

The .shtml file:

<html>
 <head>
  <title>SSI Date Test</title>
 </head>
 <body>
  The current time is :
  <b><!--#echo var="DATE_LOCAL"--></b>
  <br>
  But the time looks nicer this way :
  <!--#config timefmt="It's <b>%A</b> and the time is <b>%I:%M %p</b>!"-->
  <!--#echo var="DATE_LOCAL"-->
  <hr>
 </body>
</html>

Will result in something similar to the following being sent to the client:

<html>
 <head>
  <title>SSI Date Test</title>
 </head>
 <body>
  The current time is :
  <b>08:00:35 PM 06/02/97</b>
  <br>
  But the time looks nicer this way :
  It's <b>Monday</b> and the time is <b>08:00 PM</b>!
  <hr>
 </body>
</html>

We are even able to include HTML tags in the text string which defined the date.

Content Manager [Administrator] 16 December 2005  Permalink  
Download Free Trial

Recent Articles

Other Resources



www.zeus.com