in reply to Re^2: Comparing Dates
in thread Comparing Dates
use Time::Local qw( timelocal ); sub get_time_from_local_time_string { my ($time_string) = @_; my ($M, $D, $Y, $h, $m, $s, $ampm) = $time_string =~ m{(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+) (\w+)}; if ($h == 12) { $h -= 12 if lc($ampm) eq 'am'; } else { $h += 12 if lc($ampm) eq 'pm'; } return timelocal($s, $m, $h, $D, $M-1, $Y); } my $time1 = get_time_from_local_time_string($time_string_1); my $time2 = get_time_from_local_time_string($time_string_2); if (abs($time1 - $time2) > 72*60*60) { ... }
References:
Time::Local
localtime
Update: Application of AM/PM was incorrect. Fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Comparing Dates
by perl_99_monk (Novice) on Mar 13, 2006 at 21:58 UTC | |
by ikegami (Patriarch) on Mar 13, 2006 at 23:03 UTC | |
by perl_99_monk (Novice) on Mar 14, 2006 at 15:23 UTC | |
by ikegami (Patriarch) on Mar 14, 2006 at 15:36 UTC | |
by perl_99_monk (Novice) on Mar 14, 2006 at 16:04 UTC | |
| |
by perl_99_monk (Novice) on Mar 14, 2006 at 19:55 UTC |