time() function

The time() function converts a value to a time value.

time(v: "2016-06-13T17:43:50.1004002Z")



The value to convert. String values must be formatted as RFC3339 timestamps.

time() assumes all numeric input values are nanosecond epoch timestamps.


Convert a string to a time value

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

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

Convert an integer to a time value

time(v: 609459200000000000)

// Returns 2021-01-01T00:00:00Z

Convert all values in a column to time values

If updating values in the _value column, use toTime(). To update values in columns other than _value:

  1. Use map() to iterate over and update all input rows.
  2. Use time() to update the value of a column.

The following example uses data provided by the sampledata package to show how time() transforms data.

import "sampledata"

data =
    |> map(fn: (r) => ({r with _value: r._value * 1000000000}))
    |> rename(columns: {_value: "foo"})

    |> map(fn: (r) => ({r with foo: time(v:}))

View input and output

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.