In my script I'm storing the current in date in a variable, however I would like the variable to store the date 5 minutes ahead.
29/10/2014-10:47:06 to 29/10/2014-10:52:06
Is there a quick and easy way to do this in Bash? Looking for a solution that would also work correctly if the time was 10:59:00 for example (recognising to enter the next hour).
I've found some Perl solutions but nothing for Bash.
You can use the -d
option:
$ date
mercredi 29 octobre 2014, 11:45:45 (UTC+0100)
$ date -d '5 mins'
mercredi 29 octobre 2014, 11:50:55 (UTC+0100)
And if you want to use a variable:
$ curr=$(date +%d/%m/%Y-%H:%M:%S)
$ echo $curr
29/10/2014-11:59:50
$ date -d "($cur) +5mins" +%d/%m/%Y-%H:%M:%S
29/10/2014-12:04:54
you need to use -d option, with any user defined date:
date -d '2014/10/29 10:58:06 5 minutes'
Wed Oct 29 11:03:06 IST 2014
for current date
date -d '5 minutes'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With