Issue
So I'm trying to get a date, 1 minute into the future, but not allow midnight rollover, e.g.
date -d "23:58:42 300 seconds" +%H:%M:%S
returns "00:03:42", however I want it to be capped at "23:59:59". Any ideas how?
Solution
300 seconds is not a minute, but, the easiest way would be a simple script:
#!/bin/bash
t="$1"
interval="$2"
h=$(date -d "$t $interval seconds" +%H)
if [ "$h" = "00" ] ; then
echo "23:59:59"
else
date -d "$t $interval seconds" +%H:%M:%S
fi
This works well if your interval is under an hour.
Answered By - Ljm Dullaart Answer Checked By - David Goodson (WPSolving Volunteer)