Reputation: 129
I need to calculate in redhsift sql the week number of the year starting from sunday to saturday and starting with the first of January but truncating the first week after the occurence of the first saturday. Kinda like WEEKNUM() works in excel:
so for example in 2020 it will be (mm/dd/yyyy)
while:
How can I achieve this?
Upvotes: 1
Views: 1987
Reputation: 1240
This gives a week number that AFAICT follows the behavior of Excel and MSSQL:
case when to_char(date_trunc('year', some_date), 'iw') = '01'
then to_char(some_date + '1 day'::interval, 'iw')
else to_char(some_date + '8 days'::interval, 'iw')
end
Upvotes: 1