During a recent SQL training session one of the delegates asked "How Do I calculate the day of the week that an order was placed?"
Solution:
To calculate the name part of any datetime field in SQL, one must use the DateName function:
SELECT DATENAME(DW, Tablename.Fieldname) AS [Order Day]
FROM Tablename
Note: This returns the full day of the week, i.e. Monday, to return the abbreviated day of the week, amend the SQL syntax to the following:
DATENAME(DW, Tablename.Fieldname, TRUE) AS [Order Day]
If you have any questions, leave us a comment below, or need any assistance, please do not hesitate to Contact Us |