Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Returns a character string representing the specified datepart of the specified date.
DATENAME ( datepart , date )
datepart
Is the parameter that specifies the part of the date to return. For more information, see the "Remarks" section later in this topic.date
Is an expression that returns a datetimevalue, or a value that can be implicitly converted to a datetime value. datecan also be a Unicode character string in a date format. Use the datetime data type for dates after January 1, 1753. Store them as character data for earlier dates. When you enter datetime values, always enclose them in single quotation marks.If you specify only the last two digits of the year, values less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values greater than the last two digits of the value of this option are in the century that precedes the cutoff year. For example, if the two digit year cutoff is 2049 (the default value), the '49' is interpreted as 2049 and '50' is interpreted as 1950. To avoid ambiguity, use four-digit years.
For more information about specifying dates, see datetime in Data Types.
nvarchar
SQL Server Compact automatically converts between character and datetime values as necessary, such as when you compare a character value with a datetime value.
The following table lists the datepart options and abbreviations recognized by SQL Server Compact.
Datepart |
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 |
* The weekday (dw) datepart returns the day of the week, for example, Monday.
The following example extracts the month name from the date returned by GETDATE.
SELECT DATENAME(month, OrderDate) AS "Month Name" FROM Orders
This is the result set:
Month Name
------------------------------
August