SQL SERVER – Finding Day Name from Date

In today’s blog post we will a very simple script where we will find day name from any valid date. There are multiple ways you can do it and we will see it in multiple ways.

SQL SERVER - Finding Day Name from Date fndate-800x304

In our example, we will be using the date of today which is July 27, 2020, and it is Monday today.

Method 1: DateName() Function for Day Name

This is one of the most popular methods.

DECLARE @DateVal DATE = '2020-07-27';
SELECT @DateVal As [Date], 
	DATENAME(WEEKDAY, @DateVal) AS [Day Name];

When you run the above script you will see the date which is passed along with the day name.

Instead of weekday you can also use the abbreviation for it which is dw or w and it will give you the same result.

DECLARE @DateVal DATE = '2020-07-27';
SELECT @DateVal As [Date], 
	DATENAME(WEEKDAY, @DateVal) AS [Day Name],
	DATENAME(DW, @DateVal) AS [Day Name],
	DATENAME(W, @DateVal) AS [Day Name];

Another method is to use the format function.

Method 2: FORMAT Function

Here is how you can use the format functions to get the date name from the date.

DECLARE @DateVal DATE = '2020-07-27';
SELECT @DateVal As [Date], 
	FORMAT(@DateVal, 'dddd') AS [Day Name]

The query above will give us the day name from the date.

Here are a few additional blog posts which are related to this topic:

Well, that’s it for today. If you want me to blog about any trick or trick, just leave a comment and I will be happy to blog about it with due credit to you. You can also connect with me via LinkedIn.

Reference: Pinal Dave (https://blog.sqlauthority.com)

SQL DateTime, SQL Function, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Counter Temp Tables For Destruction Not Working
Next Post
SQL SERVER 2019 – Disabling Scalar UDF Inlining

Related Posts

Leave a Reply