DATEPART
Returns an integer that represents the specified datepart of the specified date.
Syntax
DATEPART ( datepart , date )
Arguments
datepart
Is the part of the date to return. The following table lists all valid datepart arguments. User-defined variable equivalents are not valid.
datepart | Abbreviations |
---|---|
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw, w |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
microsecond | mcs |
nanosecond | ns |
TZoffset | tz |
ISO_WEEK | ISOWK, ISOWW |
date
Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value. date can be an expression, column expression, user-defined variable, or string literal.
To avoid ambiguity, use four-digit years.
Return types
int
Example
SELECT DATEPART(second, '2007-05-07 12:10:30.123');