Hi,
Hello,
I've got a phone record that keeps the date and time in the following format:
YYMMDDHHMM example: 0501201500
So, I've written the following to convert it to the format:
MM/DD/YYYY,HH:MM example: 01/20/2005,15:00
sub convertdate {
my($locdate)[EMAIL PROTECTED];
$ypfix=20;
@ardate = split(//,$locdate);
$year=join('',$ardate[0],$ardate[1]);
$month=join('',$ardate[2],$ardate[3]);
$day=join('',$ardate[4],$ardate[5]);
$hour=join('',$ardate[6],$ardate[7]);
$minute=join('',$ardate[8],$ardate[9]);
$jyear=join('',$ypfix,$year);
$jdate=join('/',$month,$day,$jyear);
$jtime=join(':',$hour,$minute);
$retdate=join(',',$jdate,$jtime);
open ( LOG, ">>$log" ); print LOG "$retdate";
close ( LOG );
}
This works, but strikes me as ugly. Is there a more elegant way of doing what I've done here? It seems like I should be able to loop through the $ardate[n] entries and select them somehow instead of hard coding the indexes, but nothing is coming to mind.
sub convertdate { my $locdate = shift;
open my $LOG, '>>', $log or die "Cannot open $log: $!";
printf $LOG '%02d/%02d/20%02d,%02d:%02d', ( $locdate =~ /\d\d/g )[ 1, 2, 0, 3, 4 ];
close $LOG; }
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>