Home > Enterprise >  SQL Server 2017 Convert Date Column to Day of Week
SQL Server 2017 Convert Date Column to Day of Week

Time:08-05

Is there any way on SQL to copy a date column and convert it so it states the day of the week (Monday, Tuesday etc). I have read about DATEPART/DATENAME syntax but I would have to add the dates manually etc myself to convert. is there any way SQL can read the entire Date column and convert it?

CodePudding user response:

Definitely a misunderstanding on my part. Still very new to SQL. For anyone with the same issue as mine. I just did the below:

WHERE
 DATENAME(Weekday, OrderDate) IN ('Saturday)

I didn't think it would work because the column states numeric dates like '2022-07-16', instead of 'Monday, Tuesday, Wednesday...' etc. If that makes sense.

Cheers

CodePudding user response:

Seems like you are looking for a Persisted Computed column

ALTER TABLE YourTable
ADD DOW AS (datename(WEEKDAY,orderdate)) PERSISTED;
  • Related