in reply to Morning or Night?

Hmm. I think you might want to revisit your logic here a bit. Im at a loss as to how you _ever_ get the correct time from this code. In fact the entire thing looks a bit disturbing. (Hardcoded _two_digit_ year!?) I suggest you have a look at the POSIX module and more specifically the strftime() subroutine.

However if you are as determined to reinvent the wheel as I am on occasion then I will state my concerns. the hour field returned from localtime() is in the range 0..23 yet you add 1 to it before beginning, now perhaps you are doing this to adjust for a timezone, but if you think it through it doesnt work. After the addition the hour field is in the range 1..24, so when exactly will we see 12:30AM? (Never.) UPDATE: Oops. Im not entirely correct here. A more complicated AMPM logic does work, but id still say to follow the advice at the bottom.

Anyway, perhaps the below will help

my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, isdst) = loca +ltime(time); my $ampm=$hour>11 ? 'PM' : 'AM'; # day or night $hour%=12; # put it in the range 0..11 $hour=12 unless $hour; # convert 0 to 12 print "$hour$ampm"; # print it out
Now this will work for the current time zone, adjusting it for a different time zone simply requires adding the appropriate number of seconds to the value returned by time() when calling localtime()
my $hour_secs = 60*60; my @timeparts = localtime(time()+$hour_secs);
BTW, you might try writing a loop that goes from 0..23 and then print out the results of your solution for each value.

Yves / DeMerphq
--
When to use Prototypes?