Hi a few years ago I've written a perl function to calculate the difference between two dates in perl.
sub timeDiff { local our $invoke = shift || ''; local our $date1 = shift || ''; local our $date2 = shift || ''; #'2005-08-02 0:26:47', date2 => '2005-08-03 13:27:46' local our @offset_days = qw(0 31 59 90 120 151 181 212 243 273 30 +4 334); local our $year1 = substr($date1, 0, 4); local our $month1 = substr($date1, 5, 2); local our $day1 = substr($date1, 8, 2); local our $hh1 = substr($date1,11, 2) || 0; local our $mm1 = substr($date1,14, 2) || 0; local our $ss1 = substr($date1,17, 2) if (length($date1) > 16); #$ss1 ||= 0; local our $year2 = substr($date2, 0, 4); local our $month2 = substr($date2, 5, 2); local our $day2 = substr($date2, 8, 2); local our $hh2 = substr($date2,11, 2) || 0; local our $mm2 = substr($date2,14, 2) || 0; local our $ss2 = substr($date2,17, 2) if (length($date2) > 16); #$ss2 ||= 0; local our $total_days1 = $offset_days[$month1 - 1] + $day1 + 365 * + $year1; local our $total_days2 = $offset_days[$month2 - 1] + $day2 + 365 * + $year2; local our $days_diff = $total_days2 - $total_days1; local our $seconds1 = $total_days1 * 86400 + $hh1 * 3600 + $mm1 * +60 + $ss1; local our $seconds2 = $total_days2 * 86400 + $hh2 * 3600 + $mm2 * +60 + $ss2; local our $ssDiff = $seconds2 - $seconds1; local our $dd = int($ssDiff / 86400); local our $hh = int($ssDiff / 3600) - $dd * 24; local our $mm = int($ssDiff / 60) - $dd * 1440 - $hh * 6 +0; local our $ss = int($ssDiff / 1) - $dd * 86400 - $hh * 360 +0 - $mm * 60; return "$dd J $hh H $mm M $ss Sec"; }
But the result is not correct anymore it's give the resultat for the difference between today and the 2013-07-03 00:00:00 as the following result 734581 J 6 H 34 M 26 Sec where J is number of days h hours M minutes and sec seconds

In reply to DIfference in days hours and second between dates by *alexandre*

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.