in reply to Find minutes difference between two dates

thank you for ikegami and the anonymous.

ikegami: is it possible to use your method to parse date string from a csv file. coz i have lots of dates need to be calculated. can i use something like:

while ($line=<TEMP>) { my $start = $format->parse_datetime( $line[3] ); my $stop = $format->parse_datetime( $line[4] ); }

the anonymous: i have tried your code, however get the following error:

Month '12' out of range 0..11 at test.perl line 33

any suggestions for correction ?

many thanks guys ! Simon

Replies are listed 'Best First'.
Re^2: Find minutes difference between two dates
by ikegami (Patriarch) on Oct 06, 2009 at 20:49 UTC

    can i use something like:

    Yes.

    Month '12' out of range 0..11 at test.perl line 33

    Subtract 1 from the month and 1900 from the year before passing to timelocal.

Re^2: Find minutes difference between two dates
by Anonymous Monk on Oct 07, 2009 at 10:11 UTC
    any suggestions for correction ?

    Oh. I forgot that timelocal expects the month parameter to be in the range of 0..11, 0 being January and 11 being december.

    my $start_time = timelocal($start_time[5], $start_time[4], $start_time +[3], $start_time[2], $start_time[1]-1, $start_time[0]); my $end_time = timelocal($end_time[5], $end_time[4], $end_time[3], $ +end_time[2], $end_time[1]-1, $end_time[0]);
    Note the -1's.

    Ikegami's solution is much better when it comes to readability and maintainability, but mine is probably cheaper.