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
You seem to be looking for:
date -d "20170601+1 month" +%Y-%m-%d
When using multiple -d
flags in the same command, date
seems to only use the last one.
And of course, feel free to replace 20170601
by $VAR
containing any date.
For macOS High Sierra
date -v+1m -j -f "%Y-%m-%d" "2017-06-01"
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