SQL Server > Date Time related

Return week day name, week day, and month name in SQL Server

How to return Day name of the week, day of the week, and month name in SQL Server?


We can use DATENAME, DATEPART functions by passing respective parameters to return the day name of the week, day of the week and month names.

SELECT
DATENAME(WEEKDAY, GETDATE()) as DayName,
DATEPART(WEEKDAY, GETDATE()) as DayOfTheWeek,
DATENAME(MONTH, GETDATE()) As MonthName

Following are valid parameters value that can be passed to DATEPART function.

Notice that the same above result can be retrieved by passing abbreviations instead of full datepart parameter value.

SELECT
DATENAME(dw, GETDATE()) as DayName,
DATEPART(dw, GETDATE()) as DayOfTheWeek,
DATENAME(m, GETDATE()) As MonthName

Above query will give the same result as the previous one.

 Views: 67143 | Post Order: 74



Write for us






Hosting Recommendations