Printing the Current Date with Perl CGI
This Perl CGI script will print the current date on a web page.
The script can be called using SSI.
Example:
<!--#exec cgi="/cgi-bin/script.cgi"-->
Or:
<!--#include virtual="/cgi-bin/script.cgi"-->
The Perl CGI script below will print the day of the week and the month name as part of the date.
Example:
#!/usr/bin/perl use strict; print "Content-type:text/html\n\n"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; my @weekday = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my @month = qw(January February March April May June July August September October November December); $year += 1900; print "$weekday[$wday], $month[$mon] $mday, $year"; exit;
This Perl CGI script will print the date in m/d/y format. Change the output order and delimiting characters to suit your own date format preferences. Example: 12/21/2024
#!/usr/bin/perl use strict; print "Content-type:text/html\n\n"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year += 1900; $mon++; print "$mon/$mday/$year"; exit;
The output of this Perl CGI script is similar to the above except it will print the day and month as two digits, prepended with a 0 (zero) if necessary. It will print the date in mm/dd/yyyy format. Change the output order and delimiting characters to suit your own date format preferences. Example: 12/21/2024
#!/usr/bin/perl use strict; print "Content-type:text/html\n\n"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year += 1900; $mon++; $mon = "0$mon" if $mon < 10; $mday = "0$mday" if $mday < 10; print "$mon/$mday/$year"; exit;
Will Bontrager