RE: date minus one

  • From: Connor McDonald <hamcdc@xxxxxxxxxxx>
  • To: oracle-l@xxxxxxxxxxxxx
  • Date: Wed, 30 Mar 2005 14:27:44 +0100 (BST)

I don't have a unix box handy, but I dug up this from my archives

TZ=aaa24 date +%Y%m%d

hth
connor

--- "Graeme St. Clair" <Graeme.St.Clair@xxxxxxx> wrote:
> Why wouldn't you just use Perl "time() - 86400" (# seconds in a day), and
> then transform as desired with gmtime or whatever?  (In theory it might be a
> second off if you did it at half a second past a midnight with a leap
> second...)
> 
> Rgds, GStC.
> 
> 
> -----Original Message-----
> From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx]
> On Behalf Of Jared Still
> Sent: Tuesday, March 29, 2005 7:30 PM
> To: jknight@xxxxxxxxxxxxxx
> Cc: oracle-l
> Subject: Re: date minus one
> 
> And yet one more.
> 
> #!/bin/sh
> 
> # ydate: A Bourne shell script that
> # prints yestarday's date
> # Output Form: Month Day Year
> # From Focus on Unix: http://unix.about.com
> 
> # Set the current month day and year.
> month=`date +%m`
> day=`date +%d`
> year=`date +%Y`
> 
> # Add 0 to month. This is a
> # trick to make month an unpadded integer.
> month=`expr $month + 0`
> 
> # Subtract one from the current day.
> day=`expr $day - 1`
> 
> # If the day is 0 then determine the last # day of the previous month.
> if [ $day -eq 0 ]; then
> 
>   # Find the preivous month.
>   month=`expr $month - 1`
> 
>   # If the month is 0 then it is Dec 31 of
>   # the previous year.
>   if [ $month -eq 0 ]; then
>     month=12
>     day=31
>     year=`expr $year - 1`
> 
>   # If the month is not zero we need to find
>   # the last day of the month.
>   else
>     case $month in
>       1|3|5|7|8|10|12) day=31;;
>       4|6|9|11) day=30;;
>       2)
>         if [ `expr $year % 4` -eq 0 ]; then
>           if [ `expr $year % 400` -eq 0 ]; then
>             day=29
>           elif [ `expr $year % 100` -eq 0 ]; then
>             day=28
>           else
>             day=29
>           fi
>         else
>           day=28
>         fi
>       ;;
>     esac
>   fi
> fi
> 
> # Print the month day and year.
> echo "$year/$month/$day"
> exit 0
> 
> 
> 
> On Tue, 29 Mar 2005 12:55:06 -0600, Knight, Jon <jknight@xxxxxxxxxxxxxx>
> wrote:
> >   Just curious how the rest of the world gets "yesterday" in UNIX.  
> > We're running Solaris and we execute a sqlplus script with "select 
> > sysdate-1 from dual;" and pipe it to tail to set an environment variable.
> > 
> >   Is there a more UNIXy way, -or- maybe a java function.  Any 
> > suggestions welcome.
> > 
> > TIA,
> > Jon Knight
> > 
> > --
> > //www.freelists.org/webpage/oracle-l
> > 
> 
> 
> --
> Jared Still
> Certifiable Oracle DBA and Part Time Perl Evangelist
> --
> //www.freelists.org/webpage/oracle-l
> --
> //www.freelists.org/webpage/oracle-l
> 

Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
Co-author: "Oracle Insight - Tales of the OakTable"

web: http://www.oracledba.co.uk
web: http://www.oaktable.net
email: connor_mcdonald@xxxxxxxxx

"GIVE a man a fish and he will eat for a day. But TEACH him how to fish, 
and...he will sit in a boat and drink beer all day"

------------------------------------------------------------

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
--
//www.freelists.org/webpage/oracle-l

Other related posts: