0

In my Unix shell programming, I am trying to get the next date (tomorrow's date) over a reference date defined as "a". Here is the code:

a=2016-01-02 

Which operator would I use in my code so that Unix will automatically define a as tomorrow's date as in below

a=2016-01-03 
1
  • Are you using date under FreeBSD or GNU? Can you output date --version Commented Feb 24, 2017 at 17:57

1 Answer 1

2

date has a -d option that is very useful in this situation.

To get the next day, add a space after the date then add 1 day

date +%Y-%m-%d -d "$a 1 day" 

It's important to add the format specifier because without it, you would get the following output

=>"Sun Jan 3 00:00:00 UTC 2016" 

To update the a variable, you could do something like this

a=$(date +%Y-%m-%d -d "$a 1 day")

Remember to wrap the command inside of parentheses with a $ sign in front of it.

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.