0

I want to increase my time by n minute. I try the following by it does not work.

#!/bin/bash

time=$(date +'%H %M')

echo Current Time = $time
    
time=$(($time +'%2M'))
    
echo Time After 2m = $time

If my current time is e.g. 21 59 how can I increase the time by 2 minutes to have an output of 22 01 so as to be able to use it in crontab. I need my time to increase as time and not as simple numbers.

swa056
  • 95
  • 6
  • 1
    1. Get time as seconds since epoch. 2. Add 2*60 seconds. 3. Convert seconds since epoch to nice looking string representation.. – KamilCuk Jan 24 '21 at 11:21
  • I'm trying to use this code at USG-Pro Linux ver and epoch isn't install. Also, I can't use date -d "+ 1 min" parameter it shows me invalid date. – swa056 Jan 24 '21 at 12:46
  • `epoch isn't install` "Epoch" is not a command. "Epoch" is a normal word that means [a chosen time to measure events from](https://en.wikipedia.org/wiki/Epoch). There's a [unix epoch](https://en.wikipedia.org/wiki/Epoch_(computing)) that was chosen on *unix systems. Please read the answers in marked duplicates. Please read `date` man page. `I can't use date -d "+ 1 min"` So most probably you are not using GNU date implementation. – KamilCuk Jan 24 '21 at 12:50
  • How to add 2*60 seconds in an existing epoch time. What is the command? – swa056 Jan 24 '21 at 14:18
  • https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script – KamilCuk Jan 24 '21 at 14:36
  • 1
    After search this is how I do it. secs=$(date +%s) utime=$(date '+%H %M' --date="@$((secs + 120))"). Thanks for you showed me the way. – swa056 Jan 24 '21 at 14:55

0 Answers0