Skip to content

DATEPART

  • datepart: This parameter specifies the part of the date that the function will return. It can be year, quarter, month, dayofyear, day, week, weekday, hour, minute, second, millisecond, microsecond, nanosecond, tzoffset, or iso_week.
  • date: This parameter is the date value from which the function extracts the specified date part. It can be of date, smalldatetime, datetime, datetime2, datetimeoffset, or time data types.
SELECT DATEPART(year, '2021-10-01') AS Year;
Year
---------
2021

The DATEPART function extracts the specified part of the date (in this case ‘year’) from a given date. Here, the function returns ‘2021’ after extracting the year from ‘2021-10-01’.