The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 07-03-2008
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by nayanasavio View Post
hi there,
date -d '1 week ago'
or
date -d '7 days ago'
will give the date and time of exactly a week ago.
You can use '1 month ago' 'yesterday', '2 hours ago', etc..
For future dates, use 'tomorrow', '2 hours now', '1 week now', etc

Any date before/after any time period can be displayed this way.

Month=$(date -d '1 week ago' +%m)
Day=$(date -d '1 week ago' +%d)
Year=$(date -d '1 week ago' +%y)

echo $Month "/" $Day "/" $Year
this is GNU-ism and is not guaranteed to be installed.