http://www.perlmonks.org?node_id=1047981


in reply to Re^3: AM/PM to 24 hours
in thread AM to 24 hours

Here is a simple regular expression to convert a string
while (<DATA>) { s/(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)\s+(PM|AM)/$3.'-'.$1.'-'. +$2.'-'.($7 eq 'PM'?($4+12):$4).'.'.$5.'.'.$6.'.0000'/ge; print $_; } __DATA__ ID,21,11814,1,11989,150,Y,10/25/2012 11:36:25 AM,TEST ID,22,11814,1,11989,150,Y,10/25/2012 11:36:25 PM,TEST
Output:
ID,21,11814,1,11989,150,Y,2012-10-25-11.36.25.0000,TEST
ID,22,11814,1,11989,150,Y,2012-10-25-23.36.25.0000,TEST