I have a two variables :
A= 04.07.2019 23:29:40
B= 05.07.2019 01:15:52
I want to perform a arithmetic operation C = A - B
using bash.
Can some one help me in converting them into integers. In general the dates are different every time, that is why cant neglect the dates.
Output should be in seconds/minutes. If possible in HH:MM:SS
format.
You can use
date
to convert to timestamp which is seconds, subtract the seconds and then convert back toHH:MM:SS
.Unfortunately,
date
doesn't read the specified format, so we need to turn around theDD.MM.YYYY
toYYYY-MM-DD
.Output:
Using a more general function to subtract the dates:
Usage:
or if you already have
date
-compatible dates: