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.
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.
The DATENAME() function returns the date part as a character string whereas the DATEPART() returns the date part as an integer.
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.
Definition and Usage The DATEPART() function returns a specified part of a date. This function returns the result as an integer value.
select datename(weekday, getdate());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With