Retrieve and return a specific component or segment of a date.
SELECT DATEPART(year, ‘2017/08/25’) AS DatePartInt; |
The DATEPART() function retrieves a specific part of a date and returns the result as an integer value.
DATEPART(interval, date) |
Parameter |
Description |
interval |
Required: Specify the part of the date argument to retrieve. Use one of the following values:
|
Date |
Required: Specify the date to use. Acceptable data types include: date, datetime, datetimeoffset, datetime2, smalldatetime, or time. |
Return type: |
int |
Works in: |
SQL Server (beginning from 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Retrieve and provide a specific segment or component of a date.
SELECT DATEPART(yy, ‘2017/08/25’) AS DatePartInt; |
Retrieve and provide a specific segment or component of a date.
SELECT DATEPART(month, ‘2017/08/25’) AS DatePartInt; |
Retrieve and provide a specific segment or component of a date.
SELECT DATEPART(hour, ‘2017/08/25 08:36’) AS DatePartInt; |
Retrieve and provide a specific segment or component of a date.
SELECT DATEPART(minute, ‘2017/08/25 08:36’) AS DatePartInt; |