1

Looked for it for hours and nothing worked. Would really much appreciate any answer.

initial_date (format %m%d%Y) holds a value returned by an oracle database query. I want to increment this date with 1 day and use it further as an input parameter for some functions.

> echo $initial_date
02012014 

>tomorrow_date=`date +"%m%d%Y" -d ${initial_date}' + 1 day'`
date: invalid date `02012014 + 1 day'
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 4
    Possible duplicate of [How to increment a date in a bash script](https://stackoverflow.com/q/18706823/608639) – jww Sep 20 '18 at 02:01

1 Answers1

3

You need to convert the initial date to a valid format, such as yyyyMMdd first. Try:

date +"%m%d%Y" -d "${initial_date:4}${initial_date:0:4} + 1 day"
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • Worked perfectly. Thank you. Now I see where I was wrong. – user3253335 Jan 30 '14 at 14:05
  • +1. In general, http://www.gnu.org/software/tar/manual/html_node/General-date-syntax.html#SEC121 has info on what formats can be used with `-d`. OSX users: the equivalent to the above GNU date command is: `date -j -f '%m%d%Y' -v '+1d' "$initial_date" +'%m%d%Y'` – mklement0 Jan 30 '14 at 15:06