How to get day of week in Sql Server

There are certain cases where you need to get the the name of the week number or name. On Sql Server we have some functions that can help us.


You can check the following functions that can help with this task.

Datename

This function returns an string that represents the specified datepart for a given date.

Syntax

DATENAME ( datepart , date )

For this case where we need to get the name of the weekday, we are going to use the following argument.

datepartAbbreviations
weekdaydw, w

Example

SELECT DATENAME (dw , GETDATE());

Results

This returns the current date day name, This name match current day as I am executing this query on Sunday.

Day name is in english as our database language is english, if you want to return day’s name in another language you should use

SET LANGUAGE LanguageName;

Format

This function returns a value formatted with an specified format. This function works for formatting date/time and number values as strings.

Syntax

FORMAT( value, format [, culture ] )  

Example

For this example we are going to use ‘dddd’ on format as this syntax is used for getting the name of the day.

SELECT FORMAT(GETDATE(), 'dddd');

Results


Leave a Reply

Your email address will not be published. Required fields are marked *