Retrieve a particular component of a date
SELECT DATENAME(year, ‘2017/08/25’) AS DatePartString; |
The DATENAME() function retrieves a specified part of a date and returns the result as a string value.
DATENAME(interval, date) |
Parameter |
Description |
interval |
Required: Specify the part of the date to retrieve. Options include:
|
Date |
Required: Specifies a month ranging from 1 to 12. |
Return type: |
nvarchar |
Works in: |
SQL Server (beginning from 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve and return a specific component of a date.
SELECT DATENAME(yy, ‘2017/08/25’) AS DatePartString; |
Retrieve and provide a specific segment of a date.
SELECT DATENAME(month, ‘2017/08/25’) AS DatePartString; |
Retrieve and provide a specific segment of a date.
SELECT DATENAME(hour, ‘2017/08/25 08:36’) AS DatePartString; |
Retrieve a specific segment of a date
SELECT DATENAME(minute, ‘2017/08/25 08:36’) AS DatePartString; |