TSQL: A quick way to get the Day Name from a DateTime

Posted by at 30th January, 2009

create function getDayOfWeek
    (@date datetime)
returns varchar(10)
as
    begin
        declare @retVal varchar(10)
        select @retVal=
            case datepart(dw,@date)
                when 1 then 'Sun'
                when 2 then 'Mon'
                when 3 then 'Tue'
                when 4 then 'Wed'
                when 5 then 'Thu'
                when 6 then 'Fri'
                when 7 then 'Sat'
            end
        return @retVal
    end

Then you can just call it as any other function in a select (or however you need it):

select dbo.getDayOfWeek(getdate())
Category : Uncategorized

You must be logged in to post a comment.


Recent Comments
  • simplyredheads: All you lovely redheads may like to check out www.simplyredh...
  • admin: Woot - I got a response. I didn't think that there wasn't pe...
  • cyclone: You said: "There’s nothing wrong with living in a small to...
  • MrsH: You're so right, Bill! Thomas Jefferson would roll over in ...
  • Escarlata@FaireNews.com: Thanks for sharing how Golden Gate went, Bill. It sounds lik...
Flickr