$str='0501201500'; $date=join('/',substr($str,2,2),substr($str,4,2),20 . substr($str,0,2)); $time=join(':',substr($str,6,2),substr($str,8,2)); $datetime=join(',',$date,$time);
Regards Mark ----- Original Message ----- From: "Jason Balicki" <[EMAIL PROTECTED]> To: "'Perl Beginners List'" <beginners@perl.org> Sent: Friday, January 21, 2005 1:04 AM Subject: More elegant solution for a date conversion > Hi, > > 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. > > TIA, > > --J(K) > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>