1832978 Members
2761 Online
110048 Solutions
New Discussion

Re: date

 
harikrishna
Advisor

date

hi,
can anyone plz let me know how to find the previous day and date.

THANKS FOR ALL REPLIES

Regards,
HARI KRISHNA
5 REPLIES 5
Stefan Farrelly
Honored Contributor

Re: date

YESTERDAY=$(sh -c "TZ=$(date +%Z)+24; export TZ; date '+%d/%m/%y'")
echo $YESTERDAY

shows yesterdays date.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Sunil Sharma_1
Honored Contributor

Re: date

Hi,

You can see calender with command cal for current month

Sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
Elmar P. Kolkman
Honored Contributor

Re: date

Using perl, it would something like this:

perl -e 'use POSIX(strftime);print strftime("%Y/%m/%d",gmtime(time-3600*24))."\n";'

Every problem has at least one solution. Only some solutions are harder to find.
Sergejs Svitnevs
Honored Contributor

Re: date

perl -e '@TM=localtime(time-86400);printf("%02d/%02d/%02d",$TM[3],$TM[4]+1,($TM[5]+1900)%100);print("\n")'

Regards,
Sergejs
A. Clay Stephenson
Acclaimed Contributor

Re: date

Here's a method that will work for any number of days:

DATE=$(caljd.sh -S "/" $(caljd.sh -p 1))
echo "Date = ${DATE})

By changing the -p (previous) 1 to -n (next) 3, it would yield the date 3 days from now.

Also, suppose that you wanted the previous day BUT you wanted to skip weekends so that the day before Monday was to be Friday:

DATE=$(caljd.sh -S "/" $(caljd.sh -p 1 -x 0 -x 6))
echo "Date = ${DATE})

The -x 0 skips Sunday and -x 6 skips Saturday.

Invoke as caljd.sh -u for full usage.

If it ain't broke, I can fix that.