Yesterday date script

Hello All,

I am using the below script to get yesterday date, but it is giving date of day before yesterday. Right now its 080906 but this code is giving 080904. And my requirement is 080905.

#!/bin/sh
CurrentDate=`TZ="GMT+24" date +'%y%m%d'`
echo $CurrentDate;

WHY?

Please help..

Regasrds,
Waqas Ahmed

try :

date +%Y%m%d -d "yesterday" 
date +%Y%m%d -d "yesterday"

NOPE!! this is giving today's date.

Any idea about below script. sometime this script gives correct required date too.

#!/bin/sh
CurrentDate=`TZ="GMT+24" date +'%y%m%d'`
echo $CurrentDate;

Today's the 5th
Yesterday was the 4th.

I am in CST

What timezone are you in???

you need to add your offset as well as the time you want to go back.

Example, I am currently on CDT, my offset is +5, if you want date to display 24 hours ago, you would do the following:

$ date
Fri Sep  5 18:53:34 CDT 2008

$ y=`TZ=$TZ+29 date`
$ echo $y
Thu Sep 4 18:54:02 US/Central 2008

What timezone are you in?

Using the TZ variable to manipulate the date is unreliable.

If possible, use one of the versions of date that can use a different date (GNU and *BSD), or try the date shell function from Chapter 8 of my book: 8: The Dating Game

For set to privious date:-
tz=ist+24
then for reset to origional:-
tz=tz-5:30

I wasn't saying to change the TZ varable:

$ date
Fri Sep  5 22:27:19 CDT 2008
$ y=`TZ=$TZ+29 date`
$ echo $y
Thu Sep 4 22:27:24 US/Central 2008
$ date
Fri Sep  5 22:27:31 CDT 2008

I think where he was getting confused, he wasn't outputting the time, he was just outputting mm/dd/yy so depending on the time he ran the command it could of reported yesterdays date correctly for him, but other times it would of reported current date.