I want to initialise a variable with yesterday's date in a specific format, eg:
If today is 15 Feb, then variable should be var=Feb 14
.
date -d"-1day" +"%b %d"
is not working, I do not know why.
How do we do it correctly or any other way?
I want to initialise a variable with yesterday's date in a specific format, eg:
If today is 15 Feb, then variable should be var=Feb 14
.
date -d"-1day" +"%b %d"
is not working, I do not know why.
How do we do it correctly or any other way?
Assuming you are using bash:
var=`date -d"-1day" +"%b %d"`
You forgot the backticks. More visual:
var=$(date -d"-1day" +"%b %d")
Read more on Command Substitution
I use:
YESTERDAY=$(date -d yesterday '+%m/%d/%Y')
But this only works for GNU date. Please address the comments on your question, your answer depends on your version of UNIX and the tools.