Is it possible to use bash to subtract variables containing 24-hour time?
#!/bin/bash
var1="23:30" # 11:30pm
var2="20:00" # 08:00pm
echo "$(expr $var1 - $var2)"
Running it produces the following error.
./test
expr: non-integer argument
I need the output to appear in decimal form, for example:
./test
3.5
Best Answer
The
date
command is pretty flexible about its input. You can use that to your advantage:Output: