Reputation: 5249
I am trying to convert the datetime output into a date only and i would like to have it in this format:
mm/dd/yyyy
what am i doing wrong here:
select
DATEADD(DAY, CONVERT(INT,(DATEPART(WEEKDAY, dt) - 1)) * -1,dt) as [WeekBeginDate],
SUM(hours) AS TOTAL_HOURS
from myTable
where
uid = 'myUID' and dt >= CAST(DATEADD(WEEK,-5,DATEADD(DAY,(DATEPART(WEEKDAY, GETDATE()) - 1) * -1,GETDATE())) AS date) group by DATEADD(DAY, CONVERT(INT,(DATEPART(WEEKDAY, dt) - 1)) * -1,dt) order by 1
Upvotes: 0
Views: 84
Reputation: 1271151
You can use format 101 for convert:
select convert(varchar(10), dt, 101)
If you want the week begging date using your expression:
select convert(varchar(10), DATEADD(DAY, CONVERT(INT,(DATEPART(WEEKDAY, dt) - 1)) * -1,dt), 101) as [WeekBeginDate]
Upvotes: 1