Transact-SQL reference
Datename
Returns the string representing the specified date part of the specified date.
Syntax
DATENAME ( datepart , date )
Parameters
Datepart
Is a parameter that specifies the date part to be returned. The following table lists the dates and abbreviations recognized by Microsoft SQL Server.
Date |
Abbreviations |
Year |
YY, yyyy |
Quarter |
QQ, Q |
Month |
Mm, m |
Dayofyear |
Dy, y |
Day |
DD, d |
Week |
Wk, WW |
Weekday |
DW |
Hour |
HH |
Minute |
Mi, n |
Second |
SS, S |
Millisecond |
MS |
Weekday(DW) The date part returns the day of the week (Sunday, Monday, etc ).
YesDatetimeOrSmalldatetimeValue or date format string expression. For the date after January 1, January 1, 1753DatetimeData type. The earlier date is stored as character data. When you enterDatetimeAlways put the value in quotation marks. BecauseSmalldatetimeOnly accurate to minutes, so when usingSmalldatetimeThe second and millisecond values are always 0. For more information about the specified date, see datetime and smalldatetime. For more information about the time value, see time format.
If only the last two digits of the year are specified, the value is less than or equalTwo digit year cutoffThe last two-digit value of the configuration option value is in the same century as the end year. The last two-digit number greater than the value of this option is in the century before the end of the century. For example, ifTwo digit year cutoffIs 2050 (default), then 49 is interpreted as 2049,50 is interpreted as 1950. To avoid blurring, use a four-digit year.
Return type
Nvarchar
Note
SQL Server automaticallyDatetimeValues are converted as needed. For exampleDatetimeWhen the value is compared.
Example
In this example, the month name is extracted from the date returned by getdate.
SELECT DATENAME(month, getdate()) AS 'Month Name'
The following is the result set:
Month Name------------------------------February
See
Cast and convert
Data Type
Date and Time Functions