Reputation: 13
I currently have a code that takes a date and returns a Sunday Start date. What I want is to get a Monday start date instead like the weekofyear() function.
Below is my current code where evt_time is my datetime variable:
date_sub(evt_time,pmod(datediff(to_date(evt_time),'1900-01-07'),7))
For instance, I would want 6/4/2018-6/10/2018 to be group into 6/4/2018.
Upvotes: 1
Views: 2795
Reputation: 49260
Get the weekday with u
argument and then use arithmetic to get the week start date as Monday.
select date_add(to_date(evt_time)
,1-cast(from_unixtime(unix_timestamp(to_date(evt_time),'yyyy-MM-dd'),'u') as int))
Upvotes: 1