[ back to toc ]

Year 2k compliant

Date: 2002/05/25 11:04

Q:
How can I make the following script year 2k compliant?

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);

if ($sec < 10) {
$sec = "0$sec";
}
if ($min < 10) {
$min = "0$min";
}
if ($hour < 10) {
$hour = "0$hour";
}
if ($mon < 10) {
$mon = "0$mon";
}
if ($mday < 10) {
$mday = "0$mday";
}

$month = ($mon + 1);

@months =
("January","February","March","April","May","June","July","August","Septem
ber","October","November","December");

if ($use_time == 1) {
$date = "$hour\:$min\:$sec $mday/$month/$year";
}
else {
$date = "$mday/$month/$year";
}
chop($date) if ($date =~ /\n$/);

$long_date = "$mday $months[$mon] , 20$year at $hour\:$min\:$sec";
}

The script is part of the wwwboard from Matts script archive. I have
seriously modified it but am unable to get it to display the year
correctly.
It can be found at http://www.bossracing.co.uk/messageboard/index.html

I want it to display the date DD/MM/YY (UK not US configuration) I have
the month and days working ok, but not the year.

Cheers
*NAME-DELETED*
A:
Dear *NAME-DELETED*,

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

in this case sets the variable $year to contain the number of years since
1900. Thus if you want the date format in DD/MM/YY you have to insert

$year -= 100 if $year > 99;
$year = "0$year" if $year < 10;

before using the variable.

Regards,
*NAME-DELETED*r

[ back to toc ]