;

How to Get the Day of the Week from a Date in SQL Server


Tutorialsrack 13/01/2020 SQL Server

In this article, we will learn about how to get the day of the week from a date in SQL Server.

To get the day of the week from a date in SQL Server, we can use DATENAME() Built-in function:

Example 1:

Example
-- To get the Day of the Week from a current date
SELECT DATENAME(dw, GETDATE()) as 'Week Day Name';
Output

Week Day Name

------------------------------

Sunday

(1 row(s) affected)

Example 2:

Example
-- To get the Day of the Week from a given date
SELECT DATENAME(dw, '2020-02-20 15:43:46.463')  as 'Week Day Name';
Output

Week Day Name

------------------------------

Thursday

(1 row(s) affected)

Example 3:

Example
-- To get the Day of the Week from a given date
SELECT DATENAME(dw, '2020-09-19') as 'Week Day Name';
Output

Week Day Name

------------------------------

Saturday

(1 row(s) affected)

If you want the output in a different language then you have to change the login default language. To set the language you need to select the language from the System View, the query is as follows:

Example
-- To get the list of the languages
SELECT * FROM SYS.SYSLANGUAGES;

To set the language, use SET LANGUAGE statement with the  name of a language name from the sys.syslanguages System View.

Code - To Set The Language
-- Set Login Default Language
SET LANGUAGE Spanish
Example
-- To get the Day of the Week from a DateTime in the Spanish Language
SELECT DATENAME(dw, GETDATE()) as 'Week Day Name';
Output

Week Day Name

------------------------------

Domingo

(1 row(s) affected)

I hope this article will help you to understand how to get the month name from a date or using a given date in SQL Server.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags