sql server - Start the first day of the week as Sunday in SQL -
i want first day of week sunday issue code starts monday.
select uid, dateadd(dd,convert(int, (datediff(dd, '1/1/1900', t.dt)/7)) * 7,'1/1/1900') [weekbegindate], sum(hours) total_hours mytable t dt >= dateadd(week, -6, getdate()) group uid, convert(int, datediff(dd, '1/1/1900', t.dt)/7)
this should trick:
select uid, dateadd(d, -1, datediff(d, -1, t.dt)/7 * 7) [weekbegindate] , sum(hours) total_hours mytable t dt >= dateadd(week, -6, getdate()) group uid, datediff(d, -1, t.dt)/7
Comments
Post a Comment