mario kulka wrote: > hi, > My form asks for the time in the format hh? mm? am/pm? > However before I combine it all into one value (so I can insert it > into my MySQL table) I would like to change the format to military > time. I thought I could simply add 12 to the "hh" value when "am/pm" > is pm, which works fine except for 12:00AM. > So I wrote: > > if ((($ampm eq 'PM')&&($hh != 12))||(($hh == 12) && ($ampm eq > 'AM'))){$hh = $hh + 12;}
But that changes 12 AM to 24, instead of 0. Here's an example that handles it: #!/usr/bin/perl sub tomil { (shift() % 12) + (shift() =~ /^[Pp]/ && 12) } chomp, print "$_ => ", tomil(split ' ', $_), "\n" while(<DATA>); __DATA__ 12 am 1 am 11 am 12 pm 1 pm 11 pm Output: 12 am => 0 1 am => 1 11 am => 11 12 pm => 12 1 pm => 13 11 pm => 23 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]