Server Side Includes - SSI's:
Including Dates And Other Information From The Server

Overview

It is very easy to display date information on your page using includes. The following in the code
<!--#echo var="DATE_LOCAL" -->
will return this information, which is not very well displayed:
Friday, 29-Mar-2024 02:38:28 MST

Below is a table that shows you the code (argument) needed to have the server provide you with one or more parts of the date. Note that the date is based on the location of the server not local time. The argument needs to be put into other code, which will be explained further below:

Argument What it will display Results of the
include code
%a Short name of day Fri
%A Full name of day Friday
%b Short name of month Mar
%B Full month name March
%m Month number 03
%d Number of day in the month 29
%x Date in standard format 03/29/24
%y Two-digit year number 24
%Y Four-digit year 2024
%H Hour Number (24-Hour Clock) 02
%I Hour Number (12-Hour Clock) 02
%p AM or PM AM
%M Minute Number 03
%Z Time Zone MST

In the table above:

The following example code below uses the %x argument which, as you will see in the table above, provides the date in what it calls standard format. It follows here: 03/29/24 . The word echo in this context instructs the server to echo back the current status of the variable "DATE_LOCAL", which is the server's local time and date. The argument specifies what part of that date information to display:

<!--#config timefmt="%x" -->
<!--#echo var="DATE_LOCAL" -->

You can assemble more than one of the arguments shown in the table above as is seen here:

Combining several arguments
The code in the left cell below is used to display the month, day, and year.
The result is shown in the cell below on the right.
Notice that there is a comma to properly punctuate the information:
<!--#config timefmt="%b %d, %Y"-->
<!--#echo var="DATE_LOCAL" -->
Results of the code on left:
Mar 29, 2024

Assignment:

NOTE! The results of your include exercises will be posted here (as soon as I grade them).


For more information about Server Side Include dates:

In the table below are other types of information retrieved from the server using variables. The variables in the left column need to be put into the echo include's var attribute as in this example which used the first variable in the table:
<!--#echo var="HTTP_USER_AGENT" -->

Also note that the variables that result in a time have a line in the code before the echo line such as the following. This code displays the time in hours based on a 12-hour clock, minutes, AM/PM. Then the date is displayed using the code shown above in the table "Combining several arguments"):
<!--#config timefmt="%I:%M %p, %b %d, %Y"-->

Variable Name Result Description
HTTP_USER_AGENT claudebot The browser you are using, with other system information.
DATE_GMT 09:38 AM, Mar 29, 2024 Current date and time in GMT (Greenwich Mean Time)
DATE_LOCAL 02:38 AM, Mar 29, 2024 Current date and time in the local time zone
DOCUMENT_NAME includedDates.shtml The current file
HTTP_HOST www.gottheknack.com The web site that the browser requested a page from.
LAST_MODIFIED 08:28 PM, Jun 22, 2015 Last modification date and time for current file
SERVER_SOFTWARE Apache The name and version of the server software that is answering the client request.

Note that JavaScript can also be used to insert the time, date, etc., but that JavaScript code would be executed by the browser in order to get the time, with ssi it's the server that does that work.