datepart()
Returns an integer representing the specific part (century, year, month, day, day of the week, and the rest) of the given date.
Syntax
datepart(DATE, DATEPART)
Required Parameter
DATE
- Expression that returns a date type value. The function returns
null
if a value of any other type is received. DATEPART
- Constant string representing the part of the date argument to return. For a list of time units, refer to the following table.
Units of time Type Description Example century
int Century 21
day
int Date ( 1
–31
)12
decade
int Portion of the year divided by 10 201
dow
int Number of days in a week. Sunday ( 0
), Saturday (6
)1
doy
int Number of days in a year 163
epoch
long Seconds elapsed from January 1, 1970, to the date 1497269156
hour
int 24-hour standard time ( 0
–23
)21
isodow
int Number of days in a week based on ISO 8601. Monday ( 1
), Sunday (7
)1
isoyear
int The year in which the first Monday of a year is recognized as the first day of the new year (ISO 8601) 2017
microseconds
int Microseconds including seconds 56371000
millenium
int Millennium (in millennia) 3
milliseconds
int Milliseconds including seconds 56371
min
,minute
int Minute ( 0
–59
)5
mon
,month
int Month ( 1
–12
)6
msec
int Milliseconds not including seconds 377
quarter
int Quarter ( 1
–4
)2
sec
,seconds
int Second ( 0
–59
)56
timezone
int UTC standard time zone (second) 32400
timezone_hour
int UTC standard time zone (hour) 9
timezone_minute
int UTC standard time zone (minute) 0
week
int Number of weeks in which the first Monday of a year is recognized as the first day of the new year based (ISO 8601) 24
year
int Year 2017
Usage
json "{}"
| eval time=
datepart(
date("Jun 1 2020 12:34:56",
"MMM dd yyyy HH:mm:ss", "ko"),
"year"
)
=> 2020
json "{}"
| eval time=
datepart(
date("Jun 1 2020 12:34:56",
"MMM dd yyyy HH:mm:ss", "ko"),
"mon"
)
=> 6
json "{}"
| eval time=datepart(
date(
"Jun 1 2020 12:34:56", "MMM dd yyyy HH:mm:ss", "ko"),
"epoch"
)
=> 1590982496