![]() For example - if the year 2020 has 53 weeks on the 4-5-4 calendar there will be 2 versions, one that can be used to compare with the previous year(s) using the first 52 weeks - and a second one to be used to compare with following years using the last 52 weeks (restated so that week 1 becomes week 0.). For example: DATEPART ( wk, 'Jan 1, xxx x') 1 where xxxx is any year. January 1 of any year defines the starting number for the week datepart. This provides a consistent week numbering system across years.but does not necessarily allow for like-to-like comparisons.įor like-to-like comparisons, businesses will utilize a 4-5-4 type calendar (a 52/53 week calendar) and restate the calendar as needed. Week and weekday datepart arguments For a week ( wk, ww) or weekday ( dw) datepart, the DATEPART return value depends on the value set by SET DATEFIRST. ISO week 1 is the first week of the year with at least 4 days in the year, which translates to the week with the first Thursday (Monday through Thursday is the minimum number of days for the first week). Do you always want 7 days in a week? Or - do you want week one to always start on 01/01 of any given year with week 1 a shortened week (note: week 53 here will also be a shortened week). To be able to define the week number - you have to be able to define the start of the year and how the week number will be defined. It is not possible to never have a week 53.depending on when the "year" starts and ends will determine what years will have 52 weeks and what years will have 53 weeks. It extracts the year part and the week part out of a date and creates a week number like YYYY_WW. The DATEPART(week.) I quoted in the original post is actually a part of a larger function, which looks like this: RTRIM(CAST(DATEPART(year, CONVERT(datetime, CAST(DateKey AS CHAR(8)))) as char))+ '_' + RTRIM(CAST(DATEPART(week, CONVERT(datetime, CAST(DateKey AS CHAR(8)))) as char)) Ideally, I wouldn't like to see week 53 at all. It would be great to see the first week of 2021 as week 1 with just one working day (I don't really get data from Saturday and Sunday). ![]() Monday to Sunday would be good for me to consider a week.
0 Comments
Leave a Reply. |