I think this works, but sure there are better ways:
- 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;
- 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;
- 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;
- 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;
- 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