DATEPART
Function
Returns an integer representing the specified part of a date. Weekdays are numbered starting with Monday as 1,
Tuesday as 2, and so forth until Sunday as 7.
Syntax
DATEPART(date-part, date)
Parameters
-
date-part: text
One of the following predefined strings. Each date-part has abbreviated aliases that can be used in place of the longer names without affecting the behavior.year
,yy
,yyyy
quarter
,qq
,q
month
,mm
,m
dayofyear
,dy
,y
day
,dd
,d
week
,wk
,ww
weekday
,dw
hour
,hh
minute
,mi
,n
second
,ss
,s
millisecond
,ms
- date: text
A text value that can be parsed into a date/time.
Return Value
An integer representing the part of date that is specified by date-part.Example
PRINT DATEPART('month', '2016-07-23'); -- "7"
PRINT DATEPART('weekday', '2016-07-23'); -- "6"
PRINT DATEPART('dd', '2016-07-23'); -- "23"