Date command - subtract from given time

the given time is:

12:13:00

how do i subtract a 10 minutes from any given time?

date '12:13:00' '-10 min'

also tried this:

date +12:13:00 '-10 min'

I don't think that the date command is intended for that. I can sort-of get it to work by abusing the timezone concept. Note that I had to switch signs.

$ date -u -d'12:13:00' '+%H:%M:%S'
12:13:00
$
$ date -u -d'12:13:00 +0010' '+%H:%M:%S'
12:03:00
$ date -u -d'12:13:00 -0010' '+%H:%M:%S'
12:23:00
$
1 Like

It's probably too late to help SkySmart, but I thought that I would post a followup anyway. In another thread I saw Corona688 perform date arithmetic via the -d parameter to date. This led me to believe that time arithmetic should be possible too.

I had trouble getting it to work and all the problems centered around timezone computations. The first thing following the time is assumed to be a timezone offset. Therefore I had to supply a superfluous +0000 to get past that. Next I had to defeat the normal timezone computation and I used -u to do that. Putting it all together...

$
$ date  -u -d"12:13:00 +0000 -10 min" '+%H:%M:%S'
12:03:00
$ date  -u -d"12:13:00 +0000 +10 min" '+%H:%M:%S'
12:23:00
$
1 Like