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: date format WW(week number) question

Re: date format WW(week number) question

From: Ton Haver <ton.haver_at_cover.nl>
Date: Sat, 25 Sep 1999 21:41:06 +0200
Message-ID: <37ED2552.AFCAAB3B@cover.nl>


I think this works, but sure there are better ways:

  1. Determine first day of the last week of the year select to_date('31/12/1999','dd/mm/YYYY') - to_char(to_date('31/12/1999','dd/mm/YYYY'),'D') +1 from dual;
  2. Then determine weeknumber of last week and substract (weeknumber minus 1) * 7 to get date of first day of week 1 select to_date('31/12/1999','dd/mm/YYYY') - to_char(to_date('31/12/1999','dd/mm/YYYY'),'D') +1
    • (to_char(to_date('31/12/1999','dd/mm/YYYY'),'WW') -1) *7 from dual;
  3. Add 7 * weeknumberA to get first day of week A select to_date('31/12/1999','dd/mm/YYYY') - to_char(to_date('31/12/1999','dd/mm/YYYY'),'D') +1
    • (to_char(to_date('31/12/1999','dd/mm/YYYY'),'WW') -1) *7 + (40 * 7) from dual;
  4. Add 6 days to get the last day of the week select to_date('31/12/1999','dd/mm/YYYY') - to_char(to_date('31/12/1999','dd/mm/YYYY'),'D') +1
    • (to_char(to_date('31/12/1999','dd/mm/YYYY'),'WW') -1) *7 + (40 * 7) + 6 from dual;
  5. replace the "hard" week and year numbers by variables: select to_date('31/12/&&B','dd/mm/YYYY') - to_char(to_date('31/12/&&B','dd/mm/YYYY'),'D') +1
    • (to_char(to_date('31/12/&&B','dd/mm/YYYY'),'WW') -1) *7 + (&A * 7) + 6 from dual;

guerillot gil wrote:

> i know only the week number A and the year B.
>
> what kind of sql select query to write for obtain X the first day and Y the
> last day of the week
> with only the two parameters A and B?
>
> for example A=40 and B=1999.
>
> X=4/10/1999
> Y=10/10/1999 (in french format)
>
> thanks for help !!!
Received on Sat Sep 25 1999 - 14:41:06 CDT

Original text of this message

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