1835380 Members
3211 Online
110078 Solutions
New Discussion

Re: Command

 
SOLVED
Go to solution

Command

Is there any way to know yesterday's date with a command ?
6 REPLIES 6
James A. Donovan
Honored Contributor

Re: Command

# date
Wed Mar 14 11:00:53 PST 2001

Yesterday was Tue Mar 13, 2001. I know...probably not the answer you're looking for...if you describe your problem a little more, someone should be able to give you, or point you to, a script which solves it. There are many possible solutions, it just depends on what you want the end result to look like.
Remember, wherever you go, there you are...
Rita C Workman
Honored Contributor

Re: Command

Take a look at this thread, it mentions a date utility that MAY contain some command you are looking for -
and it also points to some code that may help...

http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0x5fc3854994d9d4118fef0090279cd0f9,00.html

/rcw
Mark Vollmers
Esteemed Contributor

Re: Command

Are you using this date in a script or something? If you are, you could write a script to go through and take the 'date' command. You could pull the month in one field, the day in another using grep. Then, have the script go and move back one day. For example, yesterday = today-1. You would also need to write in code so that the months would change if today was the first, and have the number of days in a month so that you had the right day when you switched months. This would be a lot of code, since you would need to specify number of days in months and check to see the what the day is and if you move months and the like. I would hope that there is an easier way, but I don't know of one. This is just a suggestion. Hope it helps.

Mark
"We apologize for the inconvience" -God's last message to all creation, from Douglas Adams "So Long and Thanks for all the Fish"
Rodney Hills
Honored Contributor
Solution

Re: Command

Here is a one line perl program

perl -e '@d=localtime(time()-86400);$d[5]+=1900;$d[4]++; print join("/",@d[4,3,5]),"\n";'
There be dragons...
Shannon Petry
Honored Contributor

Re: Command

Just thinking of different ways to do this...a pretty ease way would not work untill tomorrow, but... as root
>EDITOR=/bin/vi
>crontab -e
23 59 * * * /usr/bin/date 1>/etc/yesterday 2>>/dev/null

in a $HOME/.cshrc file>
alias yesterday '/usr/bin/cat /etc/yesterday'

Of course, there are much more creative ways to accomplish this, but this is pretty easy I think!

Regards,
Shannon
Microsoft. When do you want a virus today?

Re: Command

Thanks to all you guys, every help is well received.