There are many similarities between
DATEPARTreturns the date or time part as an integer,
DATENAMEreturns the part as a character string.
DATENAMEfunction also takes two parameters: the date or time part we want back, and the input date. Just as we saw with
DATEPART, 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.