Main Menu
Contact Bill FAQ
Linked In
Hire Bill
Bill’s Music
BW Whois
Boulder Pledge
CGI Scripts
CMS Project
Music DB
Creative HTML
The CGI Book
Perl Book
The End
· Sponsors · video tutorials
Rheumatoid Arthritis
Site Design: Bill Weinman

CGI Scripts by Bill Weinman


This is a simple "include script" for displaying the date and time on a web page. It is run from a server-side include (SSI).

On an Apache server you put something like this in your page:

  <!--#include virtual="/bw-datetime/bw-datetime.cgi" -->

The result should be something like this:

2:10 am on Friday, 2 December 2022 in Las Vegas, Nevada

Of course you can modify the text at the bottom of the script.

Here is the source code for bw-datetime.cgi. Copy/paste this code into your text editor, and make sure that the line

#!/usr/bin/perl -w
is the first line in the file.

#!/usr/bin/perl -w
# bw-datetime.cgi 
# Show the date and time on a web page.
# Copyright 2003 by Bill Weinman []
# The author grants permission to use and modify this program as you like. 
# All other rights and ownership are reserved by the author. 

use strict;

print "Content-Type: text/html\n\n";

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my @days = qw( 
  Sunday Monday Tuesday Wednesday Thursday Friday Saturday 
my @months = qw ( 
  January February March April May June July 
  August September October November December 

my $dayofweek = $days[$wday];
my $month = $months[$mon];
$year = $year + 1900;

my $meridian = ($hour > 11) ? "pm" : "am";
my $hours = ($hour > 12) ? ($hour - 12) : $hour;
my $minutes = sprintf("%02d", $min);
my $seconds = sprintf("%02d", $sec);

  "${hours}:${minutes} ${meridian} " .
  "on ${dayofweek}, ${mday} ${month} ${year} " .
  "in Las Vegas, Nevada\n";


When I was your age we had to carve our own transistors out of wood!
At BHG Worldwide Headquarters it is now ten past two, on Friday, 2 December 2022.