invisiblehand has asked for the wisdom of the Perl Monks concerning the following question:
(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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date and time difference
by haukex (Archbishop) on Jan 08, 2020 at 14:10 UTC | |
by invisiblehand (Initiate) on Jan 08, 2020 at 15:19 UTC | |
by haukex (Archbishop) on Jan 08, 2020 at 15:23 UTC | |
by invisiblehand (Initiate) on Jan 08, 2020 at 17:55 UTC | |
by haukex (Archbishop) on Jan 08, 2020 at 19:20 UTC | |
| |
by ikegami (Patriarch) on Jan 08, 2020 at 16:51 UTC | |
|
Re: date and time difference
by 1nickt (Canon) on Jan 08, 2020 at 15:10 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |