The number of date and time modules on CPAN can be overwhelming, and finding the right one for one particular situation can be quite a challenge. The modules all have their unique properties, from highly specialized (and possibly very performant) to very general and customizable. I suggest you try out a couple of them before choosing the right one for you.
$ cat 639358.pl use strict; use warnings; use Date::Calc qw(Delta_YMDHMS); use Date::Manip; use Date::Parse; use DateTime; use Benchmark qw(cmpthese); my ($d1, $d2) = ("Aug 26 23:10:59", "Aug 27 10:59:02"); sub date_manip { return UnixDate($d1, "%s") - UnixDate($d2, "%s"); } sub date_calc { return Delta_YMDHMS(2007, 8, 26, 23, 10, 59, 2007, 8, 27, 10, 59, 02 +); } sub date_parse { return str2time($d1) - str2time($d2); } sub datetime { return DateTime->new( year => 2007, month => 8, day => 26, hour => 23, minute => 10, second => 59 ) - DateTime->new( year => 2007, month => 8, day => 27, hour => 10, minute => 59, second => 02 ); } cmpthese( -1, { date_manip => \&date_manip, date_parse => \&date_parse, date_calc => \&date_calc, datetime => \&datetime } ); __END__ $ perl 639358.pl Rate date_manip datetime date_parse date_calc date_manip 310/s -- -65% -89% -100% datetime 888/s 186% -- -68% -100% date_parse 2774/s 794% 212% -- -99% date_calc 374797/s 120730% 42109% 13413% --
--
Andreas

In reply to Re: Finding the difference between 2 dates in seconds by andreas1234567
in thread Finding the difference between 2 dates in seconds by qsl

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.