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;} > > This seems to work but there must be a standard (prettier way:) to > acomplish the same. Or is that fine? >
if you don't want to concern yourself with the math, you might want to consider Date::Manip: #!/usr/bin/perl -w use strict; use Date::Manip; while(<DATA>){ chomp; print "$_ is ",UnixDate(ParseDate(s/\s/:/ && $_),"%H:%M %p"),"\n"; } __DATA__ 3 15 am 3 15 pm 7 12 pm 8 19 pm 12 10 am 1 13 pm 11 23 pm prints: 3 15 am is 03:15 AM 3 15 pm is 15:15 PM 7 12 pm is 19:12 PM 8 19 pm is 20:19 PM 12 10 am is 00:10 AM 1 13 pm is 13:13 PM 11 23 pm is 23:23 PM note that Date::Manip is huge so 1) it takes longer to load and compile. 2) it has a lot of "extra" functionalities so it's slower than the %/+12 algr. consider it only when you have heavy needs to manipulate date/time (maybe in the future ^_^ david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]