(perl version 5.8.7)

I have two date strings and and try to calculate date and time difference between two dates and times.

But the difference looks incorrect, could you help me to get the correct value?

notBefore=Nov 23 22:31:12 2019 GMT

notAfter=Mar 19 06:52:23 2020 GMT

#!/usr/bin/perl use Time::Local; # FILE READ IN $log_file = './raw.txt'; open(FH, '<', $log_file) or die $!; while (<FH>) { if(m/START/) {chomp; $sdname = $_;} if(m/notBefore/) { chomp; ($notB1, $notB2) = split('=', $_); $notB2 =~ tr/:/ /; my($mon,$mday,$hour,$minute,$sec,$year)=split(/ /,$notB2); #print $mon, $mday, $hour, $minute, $sec, $year; $time_1 = timelocal($sec,$minute,$hour,$mday,$mon,$year); } if(m/notAfter/) { chomp; ($notA1, $notA2) = split('=', $_); $notA2 =~ tr/:/ /; my($mon,$mday,$hour,$minute,$sec,$year)=split(/ /,$notA2); $time_2 = timelocal($sec,$minute,$hour,$mday,$mon,$year); } if(m/END/) {printf("%s %s %s\n", $sdname, $notB2, $notA2); print $time_2,"\n",$time_1, "\n"; $diff_time = $time_2 - $time_1; $diff_time1 = ($diff_time/86400); print "diff_time :$diff_time:$diff_time1:\n"; } }

===output=====

SD0101START Nov 23 22 31 12 2019 GMT Mar 19 06 52 23 2020 GMT

1579384343

1548250272

diff_time :31134071:360.348043981481:

========rax.txt===========

SD0101START

notBefore=Nov 23 22:31:12 2019 GMT

notAfter=Mar 19 06:52:23 2020 GMT

SD0101END

SD0201START

notBefore=Nov 24 11:11:11 2019 GMT

notAfter=Mar 19 06:52:23 2020 GMT

SD0201END


In reply to date and time difference by invisiblehand

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.