duration() function

Flux 0.7.0+

The duration() function converts a single value to a duration.

Output data type: Duration

duration(v: "1m")



(Required) Value to convert.

duration() assumes numeric input values are nanoseconds. String input values must use duration literal representation.


Convert an integer to a duration

duration(v: 120000000)
// Returns 120ms

Convert a string to a duration

duration(v: "12h30m")
// Returns 12h30m

Convert values in a column to durations

The following example uses generate.from() to generate sample data and show how to iterate over values in a stream of tables and convert them to duration values.

Flux does not support duration column types. This example converts an integer to a duration and stores the value as a string.

import "generate"

data = generate.from(
  count: 5,
  fn: (n) => (n + 1) * 3600000000000,
  start: 2021-01-01T00:00:00Z,
  stop: 2021-01-01T05:00:00Z,

  |> map(fn:(r) => ({ r with _value: string(v: duration(v: r._value)) }))

View input and output

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.