I know about Snowflake date function to find out day, week, month, year, etc. I want to have weeks start from Saturday each week to next Saturday. following gives an idea how to extract, but need something to address my specific case. How to get week number of month for any given date on snowflake SQL
If four days or more in week period belong to a certain month, I would assign the week to that month; otherwise, to the next month example: Week of April 29, 2023 to May 5, 2023 has less then four days in April so want to consider it as May Week of May 23, 2023 to June 2nd, 2023 has more than four days in May so I would like to consider it as May
I want to assign weeks to a month with more days of one month (four or more days)
Snowflake will allow you to set the first day of the week with a parameter. https://docs.snowflake.com/en/sql-reference/parameters.html#label-week-start
This will allow you to set the first day of the week at Saturday.
Doing so will result in the
WEEK()function counting weeks in a year using saturday as a delimiter between weeks.Now we just need to find which actual month has the most days for any given week and assign that week to the proper month.
I have an example script below that serves as an example on how to make a custom date dimension table. You can generate the table once and join against it to retrieve your custom date attributes.