What exactly does trunc do (date, "IW")?

For my project, I need to have an absolute numerical correspondence between the days of the week and the values ​​1 ... 7.

As you probably know, the connection between days and numbers can vary depending on the locale, for example, in Germany on Monday 1 and Sunday 7, and on Monday in the USA 2 and Sunday 1.

So, looking for a solution, I found the following code that seems to work regardless of language, assigning Monday = 1 ... Sunday = 7:

1 + TRUNC (date) - TRUNC (date, 'IW')

Can someone explain to me how this works? In particular, I just can’t understand what this instruction is:

TRUNC (date, 'IW')

for sure.

+9
source share
3 answers

TRUNC(DATE,'IW') . TRUNC(SYSDATE,'IW) . 21 . TRUNC(SYSDATE,'IW'), 20-, 1 ( 21-20=1). 1 , , 2, .

+8

, , :

IW (1-52 1-53), ISO 8601.

+7

The most basic concept of the ISO week is to make it independent of NLS .

From the documentation ,

Week of the year (1-52 or 1-53) based on the ISO standard.

Week starts on Monday and ends on Sunday .

+3
source

Source: https://habr.com/ru/post/1607607/


All Articles