Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you convert the number you get from datepart to the name of the day?

Is there a quick one-liner to call datepart in Sql Server and get back the name of the day instead of just the number?

select datepart(dw, getdate());

This will return 1-7, with Sunday being 1. I would like 'Sunday' instead of 1.

like image 660
Eric Z Beard Avatar asked Aug 15 '08 17:08

Eric Z Beard


People also ask

How do you convert a date to a day of the week in SQL?

Approach 1: Using DATENAME Function We can use DATENAME() function to get Day/Weekday name from Date in Sql Server, here we need specify datepart parameter of the DATENAME function as weekday or dw both will return the same result.

What is the difference between Datepart Datename and date?

The DATENAME() function returns the date part as a character string whereas the DATEPART() returns the date part as an integer.

How can show day name in SQL?

SELECT DATENAME(WEEKDAY, '2022-01-01' ); The result is 'Saturday'. There is also an alternative method to get a day name using the function FORMAT() . You'll need two arguments here: the first is a date and the second is a format.

What does Datepart mean in SQL?

Definition and Usage The DATEPART() function returns a specified part of a date. This function returns the result as an integer value.


1 Answers

select datename(weekday, getdate());
like image 167
Erick B Avatar answered Oct 26 '22 09:10

Erick B