in reply to calculate date difference
I don't know why you're using both DateTime and Date::Calc. Here's a solution that uses the former.
my $format = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S', time_zone => 'local', ); my $min_start = DateTime->new( year => 2007, month => 5, day => 1, tim +e_zone => 'local' ); my $max_stop = DateTime->new( year => 2008, month => 5, day => 1, tim +e_zone => 'local' );
my $start = $format->parse_datetime(...); my $stop = $format->parse_datetime(...); $start = $min_start if $start < $min_start; $stop = $max_stop if $stop >= $max_stop; my $dur = $start->delta_ms($stop); printf("%d minutes and %d seconds\n", $dur->in_units(qw( minutes secon +ds ));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: calculate date difference
by hujunsimon (Sexton) on Jul 07, 2010 at 11:04 UTC | |
by hujunsimon (Sexton) on Jul 07, 2010 at 15:22 UTC |