Operating System - HP-UX
1827089 Members
2902 Online
109713 Solutions
New Discussion

Re: how to display today - 1?

 
ericfjchen
Regular Advisor

how to display today - 1?

I will write a script to show the yesterday.
For example, today is 07/15/05, but how to get 07/14/05?

Thanks

10 REPLIES 10
Robert-Jan Goossens
Honored Contributor

Re: how to display today - 1?

Hi,

Download a copy of caljd.sh to /usr/local/bin

http://mirrors.develooper.com/hpux/caljd-2.23.sh

create a small script

#!/usr/bin/ksh
CALJD=/usr/local/bin/caljd.sh
# set date 1 day back
YESTERDAY=$($CALJD -Y -s $($CALJD -p +1))
echo $YESTERDAY

Regards,
Robert-Jan
Matthew_50
Valued Contributor

Re: how to display today - 1?

you can simply use following command

#TZ=GMT24 date '+%Y%m%d'
Muthukumar_5
Honored Contributor

Re: how to display today - 1?

Check this,

http://forums2.itrc.hp.com/service/forums/questionanswer.do?threadId=937198

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: how to display today - 1?

You can try with TZ (Time Zone) variable setting as,

OLDTZ=$TZ
echo "Today's Date : `date +'%x'`;
TZ=$TZ+24
echo "Yesterday's Date : `date +'%x'`"
TZ=$OLDTZ

hth.
Easy to suggest when don't know about the problem!
Yogeeraj_1
Honored Contributor

Re: how to display today - 1?

hi,

with ACS caljd.sh script (attached), you can try the following:
DT=$(caljd.sh $(caljd.sh -p 1))
echo "Date 1 days before was ${DT}"

hope this helps!
regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Geoff Wild
Honored Contributor

Re: how to display today - 1?

Mathew has it - and this way as well:

TZ=aaa24 date +%Y%m%d

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Rick Garland
Honored Contributor

Re: how to display today - 1?

DAY=`TZ=MST-17MDT date +%d`

Adjust the numeric figure for the respective time zone you are in...
Rick Garland
Honored Contributor

Re: how to display today - 1?

change the - to a + and use %D in place of %d
RAC_1
Honored Contributor

Re: how to display today - 1?

perl -e 'print scalar localtime((time-24*60*60)), "\n";'

Anil
There is no substitute to HARDWORK
H.Merijn Brand (procura
Honored Contributor

Re: how to display today - 1?

It's a FAQ

http://mirrors.develooper.com/hpux/faq.html

--8<---
How do I print Yesterday?

d3:/ 102 > echo 'Yesterday'
Yesterday
d3:/ 103 > perl -le 'print scalar localtime time - 86400'

Or use A.Clay Stephenson's date hammer, which can also be used for more complicated actions from the command line, as will using the modules Date::Calc or Date::Manip with Perl.
-->8---

Clay's date hammer also available there in both shell and perl version

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn