Export (0) Print
Expand All

DATENAME

SQL Server 2000

Returns a character string representing the specified datepart of the specified date.

Syntax
DATENAME ( datepart , date )
Arguments
datepart
Is the parameter that specifies the part of the date to return. The following table lists dateparts and abbreviations recognized by Microsoft® SQL Server™ 2000 Windows® CE Edition (SQL Server CE).
Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
weekday1 dw
hour hh
minute mi, n
second ss, s
millisecond ms

1 The weekday (dw) datepart returns the day of the week (such as Sunday or Monday).

date
Is an expression that returns a datetime value, or a value that can be implicitly converted to a datetime value. date can 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 entering datetime values, always enclose them in single quotation marks. For more information about specifying dates, see datetime in Data Types.

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 two digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years.

Return Types

nvarchar

Remarks

SQL Server CE automatically converts between character and datetime values as necessary, for example, when you compare a character value with a datetime value.

Examples

The following example extracts the month name from the date returned by GETDATE.

CREATE TABLE MyOrders (OrderID int IDENTITY(100, 1) PRIMARY KEY, CompanyName nvarchar(50), OrderDate datetime)
INSERT INTO MyOrders (CompanyName, OrderDate) VALUES ('A. Datum Corporation', GETDATE())
SELECT DATENAME(month, OrderDate) AS "Month Name" FROM MyOrders

This is the result set:

Month Name                     
------------------------------ 
August                         

Show:
© 2014 Microsoft