PDA

View Full Version : How do I change Perl '$date' format??


Tony Blah
02-23-2003, 06:49 PM
I'm try to edit the date format on the CGI Factory Message Board (http://www.cgi-factory.com/messageboard/index.shtml)

I'd like to change the date format from;

1/2/2003 18:38

to this:

01/02/2003 18:38

The code I think that needs changing in the 'View.pl' file is;

#time
chomp(@data[2]);
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(@data[2]))[0,1,2,3,4,5,6];
$sec = sprintf("%.02d",$sec);
$min = sprintf("%.02d",$min);
$hour = sprintf("%.02d",$hour);
$mday = sprintf("%.02d",$mday);
$year += 1900;
#date format
if ($date_format==1) {
$date = "$days[$wday], $months[$mon] $mday, $year at $hour:$min";
}
elsif ($date_format==2) {
$mon++;
$date = "$mday/$mon/$year $hour:$min";
}
else {
$mon++;
$date = "$mon/$mday/$year $hour:$min";
}
#
Anybody got an idea how I can do this?
.....thx

Philip M
02-23-2003, 07:19 PM
Try altering it to this:-

$mday = sprintf("%2.2d",$mday);

and add this line

$mon = sprintf("%2.2d",$mon);

I think this will do the trick!

% is format string
2 is the minimum field width
2 = the precision (2 digits)
d = integer

If still a problem you could try altering d to s (string).
String formatting in Perl is almost incomprehensible!

Tony Blah
02-23-2003, 07:52 PM
AAAAAYYYYYY!!! :D It worked......Thankyou so much, and thanks for the speedy reply.

Philip M
02-23-2003, 08:37 PM
Graag gedaan, as they say in Holland. = "It was a pleasure".