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
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.)
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.
Method 1: DateName() Function for Day Name DECLARE @DateVal DATE = '2020-07-27' ; SELECT @DateVal As [ Date ], DATENAME(WEEKDAY, @DateVal) AS [ Day Name ];
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.
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
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