trunc(date,'IW')到底是什么? [英] What exactly does trunc(date, 'IW')?
问题描述
对于我的项目,我需要在星期几和1 ... 7值之间具有绝对的数值对应关系.
For my project I need to have an absolute numerical correspondence between days of the week and 1...7 values.
您可能已经知道,天数与数字之间的关联会因地区而异,例如在德国,周一为1,周日为7,而在美国,周一为2,而周日为1.
As you probably know the association between days and numbers can vary according to the locale, for example in Germany Monday is 1 and Sunday is 7, while in US Monday is 2 while Sunday is 1.
因此,在寻找解决方案时,我发现以下代码似乎不管区域设置如何都起作用,将Monday = 1 ... Sunday = 7分配了:
So, searching for a solution, I found the following code which seems working regardless of the locale, assigning Monday=1...Sunday=7:
1 + TRUNC (date) - TRUNC (date, 'IW')
有人可以向我解释一下它是如何工作的吗?特别是我只是不明白这条指令是什么:
Can someone explain me how does it work? In particular I just can't understand what this instruction:
TRUNC (date, 'IW')
确实如此.
推荐答案
TRUNC(DATE,'IW')
返回一周的第一天.对我来说,TRUNC(SYSDATE,'IW)
返回星期一.今天是2月21日,星期二.从那个TRUNC(SYSDATE,'IW')
减去那将是20日星期一,您将得到1
(因为21-20=1
).像在方程式的开头那样在该值上添加1
,您将得到2
,我们将其与星期二关联.
TRUNC(DATE,'IW')
returns the first day of the week. For me TRUNC(SYSDATE,'IW)
returns Monday. Today is Tuesday Feb 21. Subtract from that TRUNC(SYSDATE,'IW')
which would be Monday the 20th, and you'll get 1
(because 21-20=1
). Add 1
onto that as you do in the beginning of your equation and you get 2
, which we associate with Tuesday.
这篇关于trunc(date,'IW')到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!