Shell script to print out YESTERDAY's date: MMDDYYYY

Hello all,

I have a cron job that will be renaming some mysql tables daily to back them up..

I wanted to do this from a shell script but I'm not sure how to gate 'date' to show YESTERDAYS date (since the script is run at midnight)


YESTERDAY=$(date +%m%d%Y)   - todays date just fine heh


mcaincAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
If you have GNU date (standard on all Linux systems), you can simply do

YESTERDAY=$(date --date yesterday +%m%d%Y)
0
 
aherpsCommented:
Same as above but:
YESTERDAY=$(date --date='1 day ago' +%m%d%Y)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.