Add month to a variable date in shell script

Viewed 13272

I have a date being passed into a shell script and have to add a month to that. for eg:

passed_date=2017-06-01

i need to add 1 month to it :

converted_date=2017-07-01

How can i achieve this in a shell script. I tried converting date to seconds since epoch and then adding 1 month like:

date +%s -d 20170601 -d "+1 month"

and then converting seconds back to yyyy-mm-dd by

date -d@$(date +%s -d 20170601 -d "+1 month") +%Y-%m-%d

but its basically adding 1 month to current system date

2 Answers

For macOS High Sierra

date -v+1m -j -f "%Y-%m-%d" "2017-06-01"
Related