3

I am on OSX and have a date variable stored in $d which is formatted like %Y_%m_%d. So echo $d would give something like 2016_03_29. I want to increment the day by 1 so it becomes 2016_03_30. From what I've read on this, I tried doing

date +"%Y_%m_%d" -d "${d:0}${d:4:0} + 1 day"

and

date -j -f '%Y_%m_%d' -v '+1d' "$d" +'%Y_%m_%d'

but neither worked.

How can I do this?

1 Answer 1

3

The problem lies in your input from YYYY_MM_DD. You can do:

d=2016_03_29
date +%Y_%m_%d -d  "$(echo $d | sed 's/_/-/g')+1 days"

to get

2016_03_30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .