in reply to Re: calculate date difference
in thread calculate date difference
Thanks Ikegami, i have modified my code according to your suggestions. however now i got an error message when i run the code:"use of uninitialized value in negation <-> at c:/perl/site/lib/DateTime.pm line 1693."
the code i modified as below:
#declare packages used use DateTime qw( ); use DateTime::Format::Strptime qw( ); my $format = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S', time_zone => 'local', ); while(<TEMP>) { my @line=split(";"); my @start_time1=($line[3]=~/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+ +)/); my $start_time = $format->parse_datetime($line[3]);; + #parsing start time my $stop_time = $format->parse_datetime($line[4]); + #parsing stop time $_->set_time_zone('local') for $start_time, $stop_time; print "$start_time, $stop_time\n"; my $min_start = DateTime->new( year => 2007, month => 5, day => + 1,hour=>0, minute=>0,second=>0, time_zone => 'local' ); my $max_stop = DateTime->new( year => 2008, month => 4, day => + 30, hour=>23, minute=>59,second=>59, time_zone => 'local' ); + $start_time = $min_start if $start < $min_start; $stop_time = $max_stop if $stop >= $max_stop; my $dur = $start_time->delta_ms($stop_time); print"%d minutes and %d seconds\n, $dur->in_units(qw( minutes s +econds ))"; }
many thanks for your help !
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: calculate date difference
by hujunsimon (Sexton) on Jul 07, 2010 at 15:22 UTC |