Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get day name from Datetime using SQL Server 2008 R2

I need to get day name from the given datetime using the SQL Server 2008 R2.

Example:

Given date:

'2014-11-14 00:00:00'
'2014-11-15 00:00:00'

Expected result:

Date              Day Name of Date
----------------------------------
2014-11-14        Friday
2014-11-15        Saturday
like image 586
Sarfaraz Makandar Avatar asked Nov 14 '14 06:11

Sarfaraz Makandar


People also ask

How do I extract a day from a date in SQL?

If you want to get a day from a date in a table, use the SQL Server DAY() function. This function takes only one argument – the date. This can be a date or date and time data type. (In our example, the column VisitDate is of the date data type.)

How do I get the day of 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.

How do I display a date and day in SQL?

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

How do I select weekday in SQL?

MySQL WEEKDAY() FunctionThe WEEKDAY() function returns the weekday number for a given date. Note: 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday, 5 = Saturday, 6 = Sunday.


1 Answers

select DATENAME(weekday,getdate())

SELECT CONVERT(VARCHAR(10), '2014-11-14 00:00:00', 105) AS DATE,
       Datename(weekday, '2014-11-14 00:00:00')         AS DayNameofDate 
like image 151
knkarthick24 Avatar answered Oct 21 '22 08:10

knkarthick24