Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Help on Dates

Re: Help on Dates

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 14 Aug 1998 15:54:29 GMT
Message-ID: <35e35cd3.183751951@192.86.155.100>


A copy of this was sent to "Steve Wood" <sewood_at_inair.com> (if that email address didn't require changing) On Thu, 13 Aug 1998 23:43:08 GMT, you wrote:

>I need to perform a function beginning say the fourth Sunday of May every
>year. How can I in sql calculate that date in a procedure or trigger. Let's
>say I want to check to see if it is that do then perform the calculation
>else do something else. What sql can I use to find the 4th sunday of may?
>thanks in advance
>Steve
>

A simple select can tell you that:

SQL> select
  2 next_day( last_day( to_date('01-APR-1998','dd-mon-yyyy' )), 'Sunday' )+21   3 from dual;

NEXT_DAY(



24-MAY-98 That will

1 - find the last_day in APRIL (the month before you want to find the 4'th sunday of).

2 - find the next day AFTER that day that is Sunday (so, if the last day of April is sunday, it'll still find the first Sunday in May)

3 - add three weeks to that

so, all you need to do to find the N'th DAY of any month is to find the last day of the previous month, find the next day after that and add....  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Fri Aug 14 1998 - 10:54:29 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US