Time functions return the decimal number for a particular time value, calculate the number of time units (days, months, years) between two dates, and allow to determine timestamps and timeframes, among others.
Creates a duration from the given amount and time unit.
duration(value, unit)
The data type of the returned value is duration.
data record(value = 1000, unit = "ns"),record(value = 60, unit = "s"),record(value = 1000 * 60 * 60 * 24, unit = "ms"),record(value = 24, unit = "h")| fieldsAdd duration(value, unit)
Query result:
Formats the timestamp according to a format string (using the defined interval).
Timestamps according to the ISO 8601 standard can be parsed and converted to the timestamp datatype.
All letters A to Z and a to z are reserved as pattern letters.
Any non-letter characters, other than [, ], {, }, # and the single quote will be output directly. However, it is recommended to use single quotes around all characters that you want to output directly to ensure that future changes do not affect your query. Unrecognized pattern letters result in an error. See Java DateTime Formatter for the list of supported patterns and symbols.
formatTimestamp(timestamp [, interval] [, format] [, timezone] [, locale])
The data type of the returned value is string.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd formatted = formatTimestamp(timestamp, format:"MM-dd-yyyy"),year = formatTimestamp(timestamp, format:"y"),month = formatTimestamp(timestamp, format:"M"),week = formatTimestamp(timestamp, format:"w"),dayofWeek = formatTimestamp(timestamp, format:"E", locale:"en-US"),hour = formatTimestamp(timestamp, format:"H"),time = formatTimestamp(timestamp, format:"HH:mm, VV"),timeET = formatTimestamp(timestamp, format:"HH:mm, VV", timezone:"US/Eastern")
Query result:
| timestamp | formatted | year | month | week | dayofWeek | hour | time | timeET |
|---|---|---|---|---|---|---|---|---|
2019-08-01T13:30:00.000Z | 08-01-2019 | 2019 | 8 | 31 | Thu | 15 | 15:30, Europe/Berlin | 09:30, US/Eastern |
Extracts the day of the month from a timestamp.
getDayOfMonth(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getDayOfMonth(timestamp)
Query result:
Extracts the day of the week from a timestamp.
The getDayOfWeek function always uses UTC as its timezone.
The week starts on Monday and ends on Sunday.
The numeric values represent the following days:
1 - Monday2 - Tuesday3 - Wednesday4 - Thursday5 - Friday6 - Saturday7 - SundaygetDayOfWeek(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getDayOfWeek(timestamp)
Query result:
Extracts the day of the year from a timestamp.
getDayOfYear(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getDayOfYear(timestamp)
Query result:
Extracts the end timestamp from a timeframe.
getEnd(timeframe)
The data type of the returned value is timestamp.
data record(timeframe = timeframe(from:"2019-08-01T09:30:00.000-0400", to:"2019-08-01T09:35:00.000-0400"))| fieldsAdd getEnd(timeframe)
Query result:
Extracts the hour from a timestamp.
getHour(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getHour(timestamp)
Query result:
Extracts the minute from a timestamp.
getMinute(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getMinute(timestamp)
Query result:
Extracts the month from a timestamp.
getMonth(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getMonth(timestamp)
Query result:
Extracts the start timestamp from a timeframe.
getStart(timeframe)
The data type of the returned value is timestamp.
data record(timeframe = timeframe(from:"2019-08-01T09:30:00.000-0400", to:"2019-08-01T09:35:00.000-0400"))| fieldsAdd getStart(timeframe)
Query result:
Extracts the second from a timestamp.
getSecond(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getSecond(timestamp)
Query result:
Extracts the year from a timestamp.
getYear(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getYear(timestamp)
Query result:
Extracts the week of the year from a timestamp.
getWeekOfYear(timestamp [, timezone])
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd getWeekOfYear(timestamp)
Query result:
Returns the current time as a fixed timestamp of the query start.
now()
The data type of the returned value is timestamp.
data record()| fieldsAdd now()
Query result:
Creates a timeframe structure from the given start and end timestamps.
timeframe(from [, to])
The data type of the returned value is timeframe.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd timeframe(from:timestamp - 5m, to: timestamp)
Query result:
Creates a timestamp using provided values in mandatory parameters.
timestamp(year, month, day, hour, minute, second [, millis] [, micros] [, nanos] [, timezone])
The data type of the returned value is timestamp.
data record()| fieldsAdd timestamp(year:2019, month:8, day:1, hour:13, minute:30, second:0, timezone:"UTC")
Query result:
Creates a timestamp from the given milliseconds since Unix epoch.
timestampFromUnixMillis(millis)
The data type of the returned value is timestamp.
data record(millis = 1564666200000)| fieldsAdd timestampFromUnixMillis(millis)
Query result:
Creates a timestamp from the given nanoseconds since Unix epoch.
timestampFromUnixNanos(nanos)
The data type of the returned value is timestamp.
data record(nanos = 1564666200000000000)| fieldsAdd timestampFromUnixNanos(nanos)
Query result:
Creates a timestamp from the given seconds since Unix epoch.
timestampFromUnixSeconds(seconds)
The data type of the returned value is timestamp.
data record(seconds = 1564666200)| fieldsAdd timestampFromUnixSeconds(seconds)
Query result:
Converts a timestamp into milliseconds.
unixMillisFromTimestamp(timestamp)
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd unixMillisFromTimestamp(timestamp)
Query result:
Converts a timestamp into nanoseconds.
unixNanosFromTimestamp(timestamp)
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd unixNanosFromTimestamp(timestamp)
Query result:
Converts a timestamp into seconds.
unixSecondsFromTimestamp(timestamp)
The data type of the returned value is long.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd unixSecondsFromTimestamp(timestamp)
Query result: