Thursday, 29 May 2008

Day Of Week : DateTime Formats

Many times we have to display day of week with date (like Wednesday, 05/28/2008). Getting date is ok; we have different formats (DateTime Formats). None of the formats return day of week. How to get that “Day of Week” part? Following script will help you out in getting day of week.

Create FUNCTION DayOfWeek
(
@Date as Datetime
)

Returns varchar (30)
AS
BEGIN

Declare @Return varchar (30)

Select @Return=case datepart(dw,@Date)
When 1 Then 'Sunday'
When 2 Then 'Monday'
When 3 Then 'Tuesday'
When 4 Then 'Wednesday'
When 5 Then 'Thursday'
When 6 Then 'Friday'
When 7 Then 'Saturday' End

Return @Return
END


I hope you liked this article..if yes please drop some comments

kick it on DotNetKicks.com

No comments:

Post a Comment