I'm attempting to get a day name like Friday, Saturday, Sunday, Monday, and so on from a given date. I realize there is an underlying capability that returns the day name for instance:
SELECT DATENAME(dw,'09/23/2013') as theDayName
This SQL query returns:
This is all OK. Be that as it may, I might want to separately spend Month, Day and Year.
I'm utilizing the builtin DATEPART capability to recover month, day and year from a date so I can pass it to the DATENAME capability:
SELECT DATEPART(m, GETDATE()) as theMonth -- returns 11
SELECT DATEPART(d, GETDATE()) as theDay -- returns 20
SELECT DATEPART(yy, GETDATE()) as theYear -- returns 2013
Now that I have Month, Day, Year values individually, I pass it to my DATENAME to get the Weekname of the date I want:
--my SQL query to return dayName
SELECT (DATENAME(dw, DATEPART(m, GETDATE())/DATEPART(d, myDateCol1)/ DATEPART(yy, getdate()))) as myNameOfDay, FirstName, LastName FROM myTable
This returns an incorrect Day Name. I tried to replace / with - so that in the DATENAME function my SQL query becomes:
But it still returns incorrect dayName from my SQL query. Am I missing something here?