SQL Server Admin
T-SQL Articles

December 03, 2009

How to Get the Day Name From a Date using SQL Server




A lot of users have confusions over how to get a Day Name from a Date in SQL Server. I have seen developers writing custom functions to achieve this simple requirement. The solution lies in the DATENAME function

I will take an example of the Northwind database;

SELECT OrderID, CustomerID, OrderDate,
DATENAME(dw, OrderDate) as DayName
From Orders

OUTPUT

image

Observe how we are using the DATENAME function specifying ‘dw’ or ‘weekday’ as the datepart. Simple, wasn’t it!

It helps to check the SQL Server Books Online to go through the built-in functions. It will benefit you in the long run!


Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter



 
  Feedback:

comments

0 Responses to "How to Get the Day Name From a Date using SQL Server"
 

Copyright © 2009-2011 All Rights Reserved for SQLServerCurry.com by Suprotim Agarwal | Terms and Conditions