How To Get Day Name From Date Time In SQL Server

Introduction

 

While working with the SQL Server you may need sometime to retrieve the day name from a date time stamp. If you want to find it out then you are in the right place.

Here is how to get the day name from a date time in SQL Server 2005/2008.

Query to Get Day Name From Date Time in SQL Server

 

Just execute the below query in SQL Server and you will find the current day name.
 SELECT Datename(dw, Getdate()) AS 'Day Name' 
The above select statement is taking the input as "GETDATE()" and retrieves the day name from it. If you want to use it in any procedure or user defined functions then you can replace the "GETDATE()" wiht the time stamp column name. See the below query.
 SELECT datename(dw,StartDate) AS 'Day Name' FROM MyTimeSheet
The above query selects only the day names from the table "MyTimeSheet" which has a column named "StartDate".

Happy Coding...

No comments:

Post a Comment