Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: date minus one
Alternatively, if perl arouses nausea, you can use C
(let's call this file sysdateMinus.c and the executable is sysdateMinus)
#include <stdio.h> #include <stdlib.h> #include <time.h>
int main(int argc, char **argv)
{
time_t t3, t1 =3D time(0);
struct tm t2;
int n =3D atoi(argv[1]);
t2 =3D *localtime(&t1);
t2.tm_mday -=3D n;
t3 =3D mktime(&t2);
printf("%s",ctime(&t3));
return 0;
}
then you can pass the days to subtract to the command line:
$ ./sysdateMinus 0
Tue Mar 29 15:44:13 2005
$ ./sysdateMinus 1
Mon Mar 28 15:44:17 2005
$ ./sysdateMinus 10
Sat Mar 19 15:44:19 2005
Obviously you would add error checking other functionality=20 to make it more useful...
-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Reidy, Ron
Sent: Tuesday, March 29, 2005 2:30 PM
To: jknight_at_concordefs.com; oracle-l
Subject: RE: date minus one
perl -MDate::Calc -e '@yesterday =3D3D Date::Calc::Add_Delta_Days(1, 1, =
1,
=3D
(Date::Calc::Date_to_Days(Date::Calc::Today()) - 1) -1); print =3D
@yesterday, "\n";'
prints:=3D20
20050328
-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org]On Behalf Of Knight, Jon
Sent: Tuesday, March 29, 2005 11:55 AM
To: oracle-l
Subject: date minus one
Just curious how the rest of the world gets "yesterday" in UNIX. =3D
We're
running Solaris and we execute a sqlplus script with "select sysdate-1 =
=3D
from
dual;" and pipe it to tail to set an environment variable.
Is there a more UNIXy way, -or- maybe a java function. Any =3D
suggestions
welcome.
TIA,
Jon Knight
-- http://www.freelists.org/webpage/oracle-l This electronic message transmission is a PRIVATE communication which =Received on Tue Mar 29 2005 - 15:13:28 CST
=3D
contains information which may be confidential or privileged. The information is
=3D
intended=3D20 to be for the use of the individual or entity named above. If you are =
=3D
not the=3D20 intended recipient, please be aware that any disclosure, copying, =3D distribution=3D20 or use of the contents of this information is prohibited. Please notify
=3D
the sender of the delivery error by replying to this message, or notify us
=3D
by telephone (877-633-2436, ext. 0), and then delete it from your system. -- http://www.freelists.org/webpage/oracle-l -- http://www.freelists.org/webpage/oracle-l
![]() |
![]() |