#!/usr/bin/perl use Time::Local; my $val= "Aug 26 23:10:59"; $val =~ tr/:/ /; my $val1="Aug 27 10:59:02"; $val1 =~ tr/:/ /; my %MONTH_NAMES = ( "Jan" => '01', "Feb"=> '02', "Mar" => '03', "Apr"=> '04',"May" => '05', "Jun" => '06', "Jul" => '07', "Aug" => '08', "sep" => '09', "oct" => '10', "Nov" => '11', "Dec" => '12' ); my $sysdate= `date`; chomp($sysdate); my $year=(split(/ /,$sysdate))[-1]; my($mon,$mday,$hour,$minute,$sec)=split(/ /,$val); $time_1 = timelocal($sec,$minute,$hour,$mday,$mon,$year); my($mon,$mday,$hour,$minute,$sec)=split(/ /,$val1); $time_2 = timelocal($sec,$minute,$hour,$mday,$mon,$year); print "1 :$time_1:\n"; print "2 :$time_2:\n"; $diff_time = $time_2 - $time_1; print "diff_time :$diff_time:\n"; output : 1 :1169824259: 2 :1169866742: diff_time :42483:
Is the above out put write ? ( Date Difference in Seconds )

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