1

I have a bash script that receives a date as a parameter ($1) in the format YYYYMMDD

What I need to do is subtract one day from the provided date. Lets take 20130701 as an example, after processing I expect to get 20130630.

How can I do this in bash? (One line solution gets bonus points!)

1 Answer 1

6

Assuming you have GNU date:

$ set -- 20130701 $ yesterday=$(date -d "$1 - 1 day" "+%Y%m%d") $ echo "$yesterday" 20130630 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.