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 !


In reply to Re^2: calculate date difference by hujunsimon
in thread calculate date difference by hujunsimon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.