Re: date minus one

  • From: stephen booth <stephenbooth.uk@xxxxxxxxx>
  • To: jknight@xxxxxxxxxxxxxx
  • Date: Tue, 29 Mar 2005 20:11:26 +0100

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

I've done it in a shell script before, I don't remember exactly the
commands but I do recall it was a lot more complex than it looks at
first.

As I recall it's something like:

* Get current date

* Check day value.  

* If day is later than first then decrement by 1 and  return along
with existing month and year value.

* If day is 1 and month is not 1 (i.e. it's first of any month but
January)  then decrement month by one and find last day of new month 
and put into day value.  If month is 2 (i.e. February) check if is a
leap year (year divisible by 4 but not by 400) and select 28 or 29 for
day value.

* If  day is 1 and month is 1 then decrement year and set day to 31
and month to 12.


It's a lot of nested case statements.


Stephen

-- 
It's better to ask a silly question than to make a silly assumption.
--
//www.freelists.org/webpage/oracle-l

Other related posts: