Increment date variable

hey guys,

I need to incerement the date variable for instance

echo `date '+%F %H:%M:00'`

this produces

2014-08-02 20:05:00

-I will grant this to : $Datehour and need to assign 1 hr from now to $Datelasthour
-the script time will be used to talk to DB system information.

however I need a second variable that is the exact same date + 1 hour

I need this for a script that will run between 9 am and 8 pm against a DB the time will be associated with the scheduling software and depends on business time thus I must use variables that pick system variable date and assign to a variable.
will update if my googing results in a answer, I feel like this is simple but yea any help would be awesome.

What Linux/UNIX are you running?

Rhel 5

---------- Post updated at 10:58 PM ---------- Previous update was at 10:48 PM ----------

Rhel 5

Some people may suggest calling date twice, but if you do that just before and just after a change in the minute, the two values won't be related the way you want them. (As a close to worst case, that could give you values two hours and 1 minute apart instead of one hour apart.) Try something like:

#!/bin/ksh
read d h m <<-EOF
    $(date '+%F %H %M')
EOF
now="$d $h:$m:00"
next="$d $(printf '%02d:%02d:00' $((${h#0} + 1)) $m)"

This was tested using the Korn shell, but will work with any shell that performs POSIX standard shell command substitutions and parameter expansions (including bash and ksh , among others). To see that it works, you'll need to either trace what it is doing or print the results.

It won't work after 11pm, but that doesn't seem to be a problem for you requirements.

Hey Don, I found this online. However I prefer yours :S

DATE=2013-05-25
  for i in {0..8} do  
  NEXT_DATE=$(date +%m-%d-%Y -d "$DATE + $i day")
    echo $NEXT_DATE done

Results:
05-25-2013
05-26-2013
05-27-2013
05-28-2013
05-29-2013
05-30-2013
05-31-2013
06-01-2013
06-02-2013

Don Thanks your script does the trick exactly as I need :smiley: