0

I can't understand why

SELECT YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) returns "2016"

SELECT WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) returns "52"

Can someone help me understand?

Baaju
  • 1,992
  • 2
  • 18
  • 22

2 Answers2

0

With slightly more digging got my answer from https://docs.snowflake.net/manuals/sql-reference/parameters.html#week-of-year-policy

Baaju
  • 1,992
  • 2
  • 18
  • 22
  • and would you like to explain "for yourself/others" what parameters where in play, otherwise this "question" and "answers" has little value. – Simeon Pilgrim Nov 17 '19 at 19:23
0

Here is the doc for the week of the year policy that decides how this works - https://docs.snowflake.net/manuals/sql-reference/parameters.html#week-of-year-policy

An example might help. week_of_year_policy is set to 0 by default on newly created accounts.


select YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as yow
     , WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as w;

+------+----+
|  YOW |  W |
+------+----+
| 2016 | 52 |
+------+----+

alter session set week_of_year_policy = 1;

select YEAROFWEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as yow
     , WEEK('2017-01-01T00:00:00.000+00:00'::timestamp) as w;

+------+---+
|  YOW | W |
+------+---+
| 2017 | 1 |
+------+---+
Baaju
  • 1,992
  • 2
  • 18
  • 22
Clivado
  • 16
  • 1
  • Your answer seems to show OP how to get what he needs, but perhaps might me more helpful if you could explain why. E.g. what is week_of_year_policy? Or link to docs. – MSurrow Nov 17 '19 at 22:00
  • OP had already linked to the docs in their update so I didn't duplicate, but appreciate this would have been a more complete answer. – Clivado Nov 19 '19 at 02:23