Using #config to customize time format and more
On the previous page I showed you SSI's ability to output various server information, such as the size of a file, current date and time etc. This is all great stuff, but a question that quickly follows is "Can I customize the format of the output such as of the date and time?" Sorry, got to learn to just be content! Just kidding. Yes, it's certainly possible, thanks to another SSI command called #config. Take a look at this:
<!--#config timefmt="%m/%d/%y" --> <!--#echo var="DATE_LOCAL" -->
Output: 11/21/24
Instead of a long string containing both the date and time, I've used #config to pound things into exactly the format I want. Lets see now the various parameters of the #config command at your disposal:
CODE | PURPOSE OF CODE | Sample output |
%a | abbreviated weekday name | Sun |
%A | full weekday name | Sunday |
%b | abbreviated month name | Jan |
%B | full month name | January |
%c | locale's appropriate date and time | Sun Dec 28 04:45:57 2005 |
%d | day of month - 01 to 31 | 25 |
%D | date as %m/%d/%y | 12/25/05 |
%e | day of month - 1 to 31 | 25 |
%H | hour - 00 to 23 | 15 |
%I | hour - 01 to 12 | 03 |
%j | day of year - 001 to 366 | 361 |
%m | month of year - 01 to 12 | 12 |
%M | minute - 00 to 59 | 09 |
%n | insert a newline character | |
%p | string containing AM or PM | PM |
%r | time as %I:%M:%S %p | 06:08:05 PM |
%R | time as %H:%M | 15:09 |
%S | second - 00 to 59 | 02 |
%t | insert a tab character | |
%T | time as %H:%M:%S | 15:21:07 |
%U | week number of year (Sunday is the first day of the week) - 00 to 53 | 52 |
%w | day of week - Sunday=0 | 0 |
%W | week number of year (Monday is the first day of the week) - 00 to 53 | 51 |
%x | Country-specific date format | 12/25/05 |
%X | Country-specific time format | 04:50:29 |
%y | year within century - 00 to 99 | 05 |
%Y | year as CCYY (4 digits) | 2005 |
%Z | timezone name | PST |
Here are a couple more examples:
<!--#config timefmt="%A %d %B, %Y" --> <!--#echo var="DATE_LOCAL" -->
Output: Thursday 21 November, 2024
<!--#config timefmt="%D %r"--> This document last modified: <!--#echo var="LAST_MODIFIED" -->
Output: This document last modified: 10/04/17 06:12:39 PM
Formatting file size with #config
So far on this page I've only used the #config command to format time related output. But you can also use this command on file size output:
<!--#config sizefmt="abbrev"--> <!--#fsize file="current.shtml" -->
<!--#config sizefmt="bytes"--> <!--#fsize file="current.shtml" -->
The first code tells the server to display the file size in abbreviated form, rounded to the nearest kilobytes. The second example obviously displays the size in bytes instead.
- Tutorial Introduction
- Using SSI to include the contents of an external file
- Echoing server information such as user IP, current date etc using SSI
- Using #config to customize time format and more
- Manually enabling SSI on your server