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 Parameters
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 timeTypeDescriptionExample
centuryintCentury21
dayintDate (131)12
decadeintPortion of the year divided by 10201
dowintNumber of days in a week. Sunday (0), Saturday (6)1
doyintNumber of days in a year163
epochlongSeconds elapsed from January 1, 1970, to the date1497269156
hourint24-hour standard time (023)21
isodowintNumber of days in a week based on ISO 8601. Monday (1), Sunday (7)1
isoyearintThe year in which the first Monday of a year is recognized as the first day of the new year (ISO 8601)2017
microsecondsintMicroseconds including seconds56371000
milleniumintMillennium (in millennia)3
millisecondsintMilliseconds including seconds56371
min, minuteintMinute (059)5
mon, monthintMonth (112)6
msecintMilliseconds not including seconds377
quarterintQuarter (14)2
sec, secondsintSecond (059)56
timezoneintUTC standard time zone (second)32400
timezone_hourintUTC standard time zone (hour)9
timezone_minuteintUTC standard time zone (minute)0
weekintNumber of weeks in which the first Monday of a year is recognized as the first day of the new year based (ISO 8601)24
yearintYear2017

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