[Solved] Working with date (add minutes using variables)

Dear all, today I'm scratching my head with a simple (I believe) issue.
Working with date is quite simple, so if I Need to add some seconds to current time, I'll use:

date --date='+30 seconds' +"%Y-%m-%d %H:%M:%S"

But, how to pass the value to add from a variable? I tried the following without success:

[root@RedHat5 ]# echo $COUNTER
100
[root@RedHat5 ]# date --date='+$COUNTER seconds' +"%Y-%m-%d %H:%M:%S"
date: invalid date `+$COUNTER seconds'

Any help?

---------- Post updated at 12:01 PM ---------- Previous update was at 11:56 AM ----------

OMG! It was so simple! :wall:
Sorry if I waste forum space!! :o

date --date='+'$COUNTER' seconds' +"%Y-%m-%d %H:%M:%S"

That will work, but I would have used double quotes; playing quoting games like that when not necessary makes the code more difficult to read.

 date --date="+$COUNTER seconds" +"%Y-%m-%d %H:%M:%S"
1 Like

Thanks for the tips agama! :b: