content/flux/v0/stdlib/universe/duration.md
duration() converts a value to a duration type.
duration() treats integers and unsigned integers as nanoseconds.
For a string to be converted to a duration type, the string must use
duration literal representation.
(v: A) => duration
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
({{< req >}}) Value to convert.
duration(v: "1h20m")// Returns 1h20m
duration(v: 4800000000000)
// Returns 1h20m
duration(v: uint(v: 9600000000000))// Returns 2h40m
Flux does not support duration column types. To store durations in a column, convert duration types to strings.
data
|> map(fn: (r) => ({r with _value: string(v: duration(v: r._value))}))
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| _time | tag | _value |
|---|---|---|
| 2022-01-01T05:00:00Z | t1 | -27000000 |
| 2022-01-01T09:00:10Z | t1 | 12000000 |
| 2022-01-01T11:00:20Z | t1 | 78000000 |
| 2022-01-01T16:00:30Z | t1 | 17000000 |
| 2022-01-01T19:00:40Z | t1 | 15000000 |
| 2022-01-01T20:00:50Z | t1 | -42000000 |
| _time | _value | tag |
|---|---|---|
| 2022-01-01T05:00:00Z | -27ms | t1 |
| 2022-01-01T09:00:10Z | 12ms | t1 |
| 2022-01-01T11:00:20Z | 78ms | t1 |
| 2022-01-01T16:00:30Z | 17ms | t1 |
| 2022-01-01T19:00:40Z | 15ms | t1 |
| 2022-01-01T20:00:50Z | -42ms | t1 |
{{% /expand %}} {{< /expand-wrapper >}}