Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Unix shell Question
Date and string functions are not terribly easy in Unix, and generally
involve parsing cal. So, if you want to do sysdate-1, what you would do is
this:
DAY=`date +%d`
MONTH=`date +%m`
YEAR=`date +%C%y`
echo $DAY $MONTH $YEAR
if [ $DAY = 1 ] ;
then
if [ $MONTH = 1 ] ;
then
CAL_MONTH=12 CAL_YEAR=`expr $YEAR - 1` else CAL_MONTH=`expr $MONTH - 1` CAL_YEAR=$YEAR
CAL_DAY=`expr $DAY - 1` CAL_MONTH=$MONTH CAL_YEAR=$YEAR
or, you could do this:
sqlplus << EOF
scott/tiger
spool date
select sysdate-1 from dual;
exit
EOF
grep -v SQL date.lst|tail -2|head -1
Whichever.
HTH,
Bambi.
-----Original Message-----
Sent: Thursday, February 28, 2002 3:38 PM
To: Multiple recipients of list ORACLE-L
Hi,
Need help in Unix shell.
Is there a way to compute the previous date (similar to sysdate - 1 in SQL)
using the date expression??
So if my date is 3/1/2002 I will get 2/28/20002.
TIA
Yuval.
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Bellows, Bambi
INET: BBellows_at_usg.com
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists --------------------------------------------------------------------To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). Received on Thu Feb 28 2002 - 16:31:30 CST