Gossamer Forum
Home : General : Perl Programming :

Date Routine

Quote Reply
Date Routine
I've got the following date routine:

Code:
sub get_date {

@months = ('January','Feburary','March','April','May','June','July','August','September','October','November','December');

($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$year += 1900;

$monn = $mon;
$monn += 1;

if (length($mday) == 1) {
$mday = "0".$mday;
}
if (length($mon) == 1) {
$mon = "0".$mon;
}
if (length($monn) == 1) {
$monn = "0".$monn;
}

$mysqldate = "$year-$monn-$mday";
}

Is there any way I can compress that code to make it faster?

- wil
Quote Reply
Re: [Wil] Date Routine In reply to
Code:
sub readable_date {
#-------------------------------------------------------------------
# $_[0] is the object, $_[1] is the argument

my ($sec, $min, $hour, $day, $mon, $yr, $dw, $dy, $timez) = localtime $_[1];
my (@mon) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

$yr = $yr + 1900;

return "$day-$mon[$mon]-$yr"

}

Last edited by:

PaulW: Nov 27, 2001, 8:15 AM
Quote Reply
Re: [PaulW] Date Routine In reply to
That won't make sure my date and month is in 2 digit format?

- wil