DATENAME

File this under the list of “I didn’t know that function existed”. So today I was looking to add the day of the week next to the date of previous and upcoming appointments to a report for an Oncology practice, and I thought I’d look around if there was a cleaner way of doing that and found that I could do this:

select LEFT(DATENAME(WEEKDAY,GETDATE()),3)

I’m confident some years ago I wrote something more along the lines of

select case datepart(weekday,getdate())
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'
else 'Uhh ... we got problems?'
end

Granted I was probably working with SQL Server 2000 at the time, so who knows, DATENAME may not have existed at the time, so maybe it wasn’t as terrible as I think.

This entry was posted in Uncategorized. Bookmark the permalink.