How can I get the real number of week of the year in next 6 months?
Example:
13.09.2022 is the 38th week of the year
17.09.2022 is the 38th week of the year
19.09.2022 is the 39th week of the year
.
.
01.01.2023 is the 1th week of the year (Sunday)
02.01.2023 is the 2th week of the year (Monday)
09.01.2023 is the 3th week of the year
.
Next 6 Months
I already know the real number of the week in a year but not in next 6 months, just to the end of the year in the below code.
SELECT LISTAGG (
DISTINCT TO_CHAR (TRUNC (mydate, 'MONTH'), 'MONTH'),
', ') AS MONTHS,
TO_CHAR (nr_of_sundays + 1, 'fm09') week_num
FROM (SELECT mydate,
( ( TRUNC (mydate, 'day')
- TRUNC (TRUNC (mydate, 'yyyy'), 'day'))
/ 7)
+ CASE
WHEN TO_CHAR (TRUNC (mydate, 'YYYY'), 'day') =
'sun'
THEN
1
ELSE
0
END AS nr_of_sundays
FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
FROM DUAL
CONNECT BY LEVEL <=
TRUNC (ADD_MONTHS (SYSDATE, 12),
'yy')
- TRUNC (SYSDATE, 'yy')))
WHERE TO_DATE (mydate, 'DD/MM/YY') >=
TO_DATE (SYSDATE, 'DD/MM/YY')
GROUP BY TO_CHAR (nr_of_sundays + 1, 'fm09')
ORDER BY TO_CHAR (nr_of_sundays + 1, 'fm09');
Could you guys help me?