Mohammedz.com

For Linux and Shell scripting.

How to find past/future dates?

Leave a comment


what day it was exactly one month ago? Are you counting down the days to find it? Or searching for a calender?

You can use “date” command in such situations. See the example below:

****************************************
-bash-3.1$ date +%F
2009-06-29
-bash-3.1$ date -d”1 day ago” +%F
2009-06-28
-bash-3.1$ date -d”1 week ago” +%F
2009-06-22
-bash-3.1$ date -d”1 month ago” +%F
2009-05-29
-bash-3.1$ date -d”1 year ago” +%F
2008-06-29
-bash-3.1$
****************************************

These examples will show you how to find the future dates.
****************************************
-bash-3.1$
-bash-3.1$ date +%F
2009-06-29
-bash-3.1$ date -d”-1 day ago” +%F
2009-06-30
-bash-3.1$ date -d”-1 week ago” +%F
2009-07-06
-bash-3.1$ date -d”-1 month ago” +%F
2009-07-29
-bash-3.1$ date -d”-1 year ago” +%F
2010-06-29
-bash-3.1$
****************************************

~mohammed

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s