Or try Date::Calc for similar effect as the previous response.
#!/usr/bin/env perl # use strict; use warnings; use Date::Calc qw/ Mktime /; my $date1 = "Aug 26 23:10:59"; my $date2 = "Aug 27 10:59:02"; # assume that the year needed is 2007; my $year1 = my $year2 = 2007; sub split_date_str { my %months = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4, May => 5, J +un => 6, Jul => 7, Aug => 8, Sep => 9, Oct => 10, Nov => 11, + Dec => 12 ); my $str = shift; my @f = split /\s+/, $str; my $month = $months{$f[0]} || die "invalid month in string: '$str' +\n"; ($month, $f[1], split(/:/, $f[2])); } my $diff = Mktime( $year2, split_date_str($date2) ) - Mktime( $year1, + split_date_str($date1) ); print $diff,"\n";

In reply to Re: Finding the difference between 2 dates in seconds by bruceb3
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.