I have the following query:
SELECT forecastDate, to_char(to_date(forecastDate),'WW') AS WEEK_NUMBER
FROM ACT_FORECAST
Which give me this result :
forecastDate | WEEK_NUMBER
14/07/2017 28
15/07/2017 28
16/07/2017 29
But in my region the week start on Monday, I should have 28 for the 16/07/2017.
The NLS_TERRITORY value of my DB is 'France'.
I tried multiple things but nothing worked.
Any ideas?
Thanks
Reason is the format WW
where documentation says:
WW
Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
Luckily on ISO-8601 the first day of week is also Monday, so you can use
SELECT forecastDate, to_char(to_date(forecastDate),'IW') AS WEEK_NUMBER
FROM ACT_FORECAST
IW
Calendar week of year (1-52 or 1-53), as defined by the ISO 8601 standard.
A calendar week starts on Monday.
The first calendar week of the year includes January 4.
The first calendar week of the year may include December 29, 30 and 31.
The last calendar week of the year may include January 1, 2, and 3.
And btw, you should change the data type of column forecastDate
to DATE
or TIMESTAMP
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.