Calculating time (adding minutes) bash
Asked Answered
J

1

22

I got stuck in part of the script. I have time: for example "16:00" and duration in minutes like: 410.

Is there any easy way to add those two values? I've tried a lot of combinations with date -d, but can't solve it.

Jinks answered 18/1, 2014 at 18:55 Comment(0)
C
32

Try this (Kysu's version):

date -d "16:00 410 minutes" +'%H:%M'

or this:

date -d "16:00 today + 410 minutes" +'%H:%M'

But do not use this:

date -d "16:00 + 410 minutes" +'%H:%M'   # BAD!

Strange things happen if you omit the word today but keep the +. (I think the + 410 is being parsed as a timezone modifier, and then the minutes is interpreted as "add one minute".)

Conclave answered 18/1, 2014 at 19:27 Comment(1)
well I tried without word today now it's OK. Also works well: date -d "16:00 410 minutes" +'%H:%M'Jinks

© 2022 - 2024 — McMap. All rights reserved.