in reply to Calculate time difference

I think this can be achieved with proper db query. But if you need Perl script to do this, use something like this:

$refvalues= [['1', '2008-04-04 17:30:01'], .... ['1', '2008-04-04 22:10:02']]; sub calcdiff { ($d1, $d2) = @_; return ??? } $is_in_state_0 = 0; $start_date = ''; $end_date = ''; for(@$refvalues) { if($is_in_state_0) { if($$_[0] eq '1') { $end_date = $$_[1]; $is_in_state_0 = 0; print 'status 0 detected between '.$start_date.' and '.$en +d_date.' => '. calcdiff($start_date, $end_date)."\n" } } else { if($$_[0] eq '0') { $is_in_state_0 = 1; $start_date = $$_[1]; } } }

And here you will find description how to fill calcdiff() function