I have 2 variables.
GMDCOMTM which stores the date time Tue Oct 1 13:32:40 2013
GMDRRSTM which stores the date time Tue Oct 2 23:35:33 2013
How do I calculate the difference between the 2 variables in hh:mm:ss format and store it in 3rd variable.? I dont want to use AWK, SED or PERL. I want to use simple shell script to do it.
Convert dates to
%s ---> seconds since 1970-01-01 00:00:00 UTC
.So the thing is to get the difference in seconds between both dates using
bc
as calculator:Then you can get it into hours, days, with the great function Stéphane Gimenez indicates in UNIX & Linux:
I'm normal using a custom made function to do the calculations. It may be long way but it will definitely work on all UNIX and Linux based systems. Following the code block.
Place the above code in your script and then call the function like follows.