I have a table with a datetime
column from which I need to extract the name of the day only and add to a new column like dayNameOnly
and as default there after.
I have done the same to get the DATEONLY like this, but I cannot get it working with the datename or datepart.
ALTER TABLE someTable
ADD dayNameOnly AS CAST(DATEADD(DAY, DATADIFF(DAY, 0, someDateColounm), 0) as DATE)
3条答案
按热度按时间gpnt7bae1#
You wanted the weekday name in string ?
On the query that you have shown, you do not need to perform the
dateadd/datediff
calculationCAST(DATEADD(DAY, DATADIFF(DAY, 0, someDateColounm), 0) as DATE)
. You can simplycast() or convert()
it todate
lvjbypge2#
If you are trying to add computed column
somedatecolumn
. Here's the script.or, if you want to extract the
weekday
name as a computed column.mbskvtky3#