* Tong * wrote:
> Hi,
>
> I'm wondering which package can do time diff calculation. I.e., something
> that can do time_diff 0:40:33 0:28:50 and gives me 00:11:43.
>
> I've tried Date::Simple, Date::Calc, Class:
ate and DateTime, but none
> of them can. Maybe I'm too blunt, so I'm not going to show my stupid
> trials here.
>
> Thanks for your help.
>
I don't know how the Ruby solution will help you out, but Date::Calc is
my preferred *Perl* module. However, when comparing times with
Date::Calc you need to pass it the date (year, month, day) as well. For
this example I used Date::Calc's Today function for that. If you
determine the correct date, then Date::Calc will correctly calculate the
time diff when spanning different days.
use Date::Calc qw(Today Delta_YMDHMS);
my $end = q/0:40:33/;
my $start = q/0:28:50/;
my ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) =
Delta_YMDHMS(Today(), (split /:/, $start) ,
Today(), (split /:/, $end) );
printf "Start: %s End: %s Diff: %02d:%02d:%02d",
$start, $end, $Dh, $Dm, $Ds;
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----