Back to Influxdb

time() function

content/flux/v0/stdlib/universe/time.md

latest4.0 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L3393-L3393 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

time() converts a value to a time type.

Function type signature
js
(v: A) => time

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

v

({{< req >}}) Value to convert.

Strings must be valid RFC3339 timestamps. Integer and unsigned integer values are parsed as nanosecond epoch timestamps.

Examples

Convert a string to a time value

js
time(v: "2021-01-01T00:00:00Z")// Returns 2021-01-01T00:00:00Z (time)


Convert an integer to a time value

js
time(v: 1640995200000000000)// Returns 2022-01-01T00:00:00Z


Convert all values in a column to time

If converting the _value column to time types, use toTime(). If converting columns other than _value, use map() to iterate over each row and time() to convert a column value to a time type.

js
data
    |> map(fn: (r) => ({r with exampleCol: time(v: r.exampleCol)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tagexampleCol
2021-01-01T00:00:00Z-2t1-2000000000
2021-01-01T00:00:10Z10t110000000000
2021-01-01T00:00:20Z7t17000000000
2021-01-01T00:00:30Z17t117000000000
2021-01-01T00:00:40Z15t115000000000
2021-01-01T00:00:50Z4t14000000000
_time_value*tagexampleCol
2021-01-01T00:00:00Z19t219000000000
2021-01-01T00:00:10Z4t24000000000
2021-01-01T00:00:20Z-3t2-3000000000
2021-01-01T00:00:30Z19t219000000000
2021-01-01T00:00:40Z13t213000000000
2021-01-01T00:00:50Z1t21000000000

Output data

_time_valueexampleCol*tag
2021-01-01T00:00:00Z-21969-12-31T23:59:58Zt1
2021-01-01T00:00:10Z101970-01-01T00:00:10Zt1
2021-01-01T00:00:20Z71970-01-01T00:00:07Zt1
2021-01-01T00:00:30Z171970-01-01T00:00:17Zt1
2021-01-01T00:00:40Z151970-01-01T00:00:15Zt1
2021-01-01T00:00:50Z41970-01-01T00:00:04Zt1
_time_valueexampleCol*tag
2021-01-01T00:00:00Z191970-01-01T00:00:19Zt2
2021-01-01T00:00:10Z41970-01-01T00:00:04Zt2
2021-01-01T00:00:20Z-31969-12-31T23:59:57Zt2
2021-01-01T00:00:30Z191970-01-01T00:00:19Zt2
2021-01-01T00:00:40Z131970-01-01T00:00:13Zt2
2021-01-01T00:00:50Z11970-01-01T00:00:01Zt2

{{% /expand %}} {{< /expand-wrapper >}}