SQL Server Docs

DATEPART (Transact‑SQL)

Returns an integer representing the specified part of a date.

Syntax

DATEPART ( datepart , date )

Parameters

ParameterDescription
datepartPart of the date to return. See datepart values.
dateAn expression that can be resolved to a datetime, datetime2, smalldatetime, date, time, or datetimeoffset value.

Return Types

Returns int.

Remarks

Examples

Example 1 – Return the month from a date

SELECT DATEPART(month, '2019-07-25') AS MonthNumber;

Example 2 – Using DATEPART with GETDATE

SELECT DATEPART(weekday, GETDATE()) AS TodayWeekday;

See also