Randolph West continues his dates and times series with a new function, DATENAME()
:
There are many similarities between
DATEPART
andDATENAME
. WhereDATEPART
returns the date or time part as an integer,DATENAME
returns the part as a character string.This
DATENAME
function also takes two parameters: the date or time part we want back, and the input date. Just as we saw withDATEPART
, the documentation indicates the input date parameter must be an “expression that can resolve to one of the following data types: date, smalldatetime, datetime, datetime2, datetimeoffset, or time.”Similarly, the date and time parts that can be returned look much like those in
DATEPART
, which gives us another opportunity for the reminder that we should avoid using the available abbreviations in order to help with writing clearly understandable code.
DATENAME
is a useful function for displaying parts of dates & times, but Randolph does lay out the caveats.