Returns a human-readable text string representing the specified part of a date. Month and day names (like "January" and "Monday") are returned according to the local computer's culture settings. Time zone offsets are returned formatted like "+02:30" or "-06:00". Other date parts are returned as numbers that have been converted to strings.
- date-part (text expression)
One of the following predefined strings. Each date-part has abbreviated aliases that can be used in place of the longer names without affecting the behavior.
- date (date/time expression)
A text value that can be parsed into a date/time with time zone offset. If no time zone is specified in the string, then the system's local time zone is assumed.
A string containing the part of date that is specified by date-part.
PRINT DATENAME('month', '2016-07-23');
Prints "July" on English systems.
PRINT DATENAME('weekday', '2016-07-23');
Prints "Saturday" on English systems.
DECLARE @x = DATENAME('dd', '2016-07-23');
Assigns the string "23" to
PRINT DATENAME('tzoffset', '2016-07-23 12:00 -04:00');