duration() function
The duration()
function converts a single value to a duration.
Output data type: Duration
duration(v: "1m")
Parameters
v
(Required) Value to convert.
duration()
assumes numeric input values are nanoseconds.
String input values must use duration literal representation.
Examples
- Convert an integer to a duration
- Convert a string to a duration
- Convert values in a column to durations
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,
)
data
|> map(fn:(r) => ({ r with _value: string(v: duration(v: r._value)) }))
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Flux and this documentation. To find support, the following resources are available:
InfluxDB Cloud customers can contact InfluxData Support.