Le 8 juil. 07 à 07:03, Ceylan, Hasan a écrit :

Hello:

Hi,

I have a question about grabing seconds between to dates. Initially I
grab the dates from a string and store them in an array. I think they
are still in string format.

You want to make sure of that. It's your program, you're the one that
decides what's in your variables!

I would like to go through the array and
subtrack last one from the previous one until it is done. Please help
me.



My array items looks like this "07/03/2007 11:47:50"  "07/03/2007
11:47:50" "07/03/2007 11:47:50"  "07/03/2007 10:48:05"

You'll want to convert those string to DateTime objects. One way to do this is

 use DateTime::Format::Strptime;
 $parser = DateTime::Format::Strptime->new(pattern => "%d/%m/%Y %T");
 $dt = $parser->parse_datetime("07/03/2007 11:47:50");

(assuming 07/03 is March 7, not July 3)

Once you have 2 DateTime objects, you can subtract one from the other
using DateTime's subtract_datetime method:

 $dur = $dt2->subtract_datetime($dt1);

This is all explained in great detail in DateTime's documentation:
 http://search.cpan.org/~drolsky/DateTime-0.38/lib/DateTime.pm

--
Éric Cholet


Reply via email to