How to add 15 or 30 or 60 minutes to the time 15:00 PM..?

us flag
#the vm shutdown tag 
tag="15:00 PM"
#the "/usr/bin/input_azureuser.log" file contains snooze data in minutes
#snooze_time values will be "15,30 or 60" Minutes 
snooze_time=`cat /usr/bin/input_azureuser.log |tail -n 1 | awk '{print $8}'`


#azureuser@puppetclient-ubuntu:~$ cat /usr/bin/input_azureuser.log
Mon Sep 6 11:24:14 UTC 2021 azureuser 15
Mon Sep 6 11:36:32 UTC 2021 azureuser 30
Mon Sep 6 13:51:03 UTC 2021 azureuser 15
Mon Sep 6 13:52:31 UTC 2021 azureuser 60
Mon Sep 6 14:41:40 UTC 2021 azureuser 15

If snooze/delay_time value is 15/30/60 minutes I want to add the same values to the tag and update the tag like "15:15 PM" ,"15:30 PM" and "16:00".

24601 avatar
in flag
please explain how this relates to ubuntu after reading [ask]. [Edit] your question accordingly.
Haridvpsk avatar
us flag
I have update my question please help me on the same. Thanks in advance!
cn flag

You can use the date command to add relative offsets to dates and times.

date -d"90 minutes 15:00" '+%H:%M'

Where -d is the time and adjustment, and +... is the output format. So:

tag=`date -d"$snooze_time minutes $tag" '+%H:%M'`

would update the tag to 16:30.

Note: using AM/PM with the 24 hour clock is an error.

Haridvpsk avatar
us flag
Thank you so much @Martin the above solution is working for me.

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.