I was having a look on threads on the Forum about time calculation but didn't find exactly this issue.
For instance, if we have these 2 dates, begin & end :
20100430235830
20100501000200
Is there anyway, awk, ksh, perl to calculate the difference in sec and get for our example : 210
Noting that the script should work for all dates and time of the year ...
It means leap years, months with 30 or 31 days, ... because begin & end dates could be more then several dates.
I'm working on a :
SunOS 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Fire-V240
Note that I had to adjust the time going in with a decimal point before seconds. Depending on how/where this number is coming from, you might need to do something with strings.
file1 & file2 can be deleted when done; other filenames can be used.
I executed your perl shell but got the following errors. Do you have an idea why ??
$ cat temp.sh
perl -MTime::Local -le'
/(....)(..)(..)(..)(..)(..)/g and
push @dt, timelocal $6, $5, $4, $3, $2 - 1, $1 - 1900
for @ARGV;
print $dt[1] - $dt[0] if eof;
' 20100430235830 20100501000200
$ perl temp.sh
Number found where operator expected at temp.sh line 7, near "' 20100430235830"
(Might be a runaway multi-line '' string starting on line 2)
(Missing operator before 20100430235830?)
Number found where operator expected at temp.sh line 7, near "20100430235830 20100501000200"
(Missing operator before 20100501000200?)
syntax error at temp.sh line 2, near "-le"
Execution of temp.sh aborted due to compilation errors.
Regs,
---------- Post updated at 10:11 AM ---------- Previous update was at 10:06 AM ----------
Oh, Sorry , I got it ....
I'm typing perl twice ... I don't know well this language yet ....