Tuesday, June 3, 2014

Getting Yesterdays or Tomorrows Day With Bash Shell Date Command

GNU date syntax

The syntax is as follows:
 
date  --date="STRING"
date  --date="next Friday"
date  --date="2 days ago"
 

Getting Date In the Future

To get tomorrow and day after tomorrow (tomorrow+N) use day word to get date in the future as follows:
date --date='tomorrow'  
date --date='1 day'  
date --date='10 day'  
date --date='10 week'
date --date='10 month'  
date --date='10 year'

How Do I Assigned Yesterday To Shell Variable?

yest=$(date --date="2 days ago")
echo "$yest" yest=$(date --date="yesterday" +"%d/%m/%Y")  
echo "The backup was last verified on $yest"

 

No comments:

Post a Comment