[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shell Script , 2 days back date required.

Posted on 2011-10-14
4
Medium Priority
?
335 Views
Last Modified: 2012-05-12
Need day before yesterday's date from the system though shell command.


I have one for yesterday , but i am looking for day before yesterday.

DATE=$(date -d yesterday +"%Y%m%d")

$ export YD=$(date --date yesterday +%Y%m%d)
$ date
Fri Oct 14 15:08:28 EDT 2011
$ export YD=$(date --date yesterday +%Y%m%d)
$ echo $YD
20111013

I am looking for 20111012
0
Comment
Question by:ratna1234
4 Comments
 
LVL 6

Accepted Solution

by:
Gerald26 earned 2000 total points
ID: 36966933
export YD=$(date --date '2 days ago'  +%Y%m%d)

0
 
LVL 23

Expert Comment

by:Kamaraj Subramanian
ID: 36967116
date -d "2 days ago" +%Y%m%d

Open in new window

0
 
LVL 2

Expert Comment

by:DaemonBarber
ID: 36968727
Worth noting that the -d option to date is not available on all systems (solaris for example).

Try this when not available:

perl -e 'print scalar localtime(time - 86400 * 2)'

0
 

Author Closing Comment

by:ratna1234
ID: 36973502
Thanks,
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question