---
title: duration() function
description: duration() converts a value to a duration type.
url: https://docs.influxdata.com/flux/v0/stdlib/universe/duration/
estimated_tokens: 653
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/universe/duration/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.7.0+

InfluxDB support

`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.

##### Function type signature

```js
(v: A) => duration
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### v

(Required)
Value to convert.

## Examples

* [Convert a string to a duration](#convert-a-string-to-a-duration)
* [Convert numeric types to durations](#convert-numeric-types-to-durations)
* [Convert values in a column to durations](#convert-values-in-a-column-to-durations)

### Convert a string to a duration

```
duration(v: "1h20m")// Returns 1h20m

```

### Convert numeric types to durations

```
duration(v: 4800000000000)

// Returns 1h20m
duration(v: uint(v: 9600000000000))// Returns 2h40m

```

### Convert values in a column to durations

Flux does not support duration column types.
To store durations in a column, convert duration types to strings.

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

[](#view-example-input-and-output)

View example input and output

#### Input data

|       \_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|

#### Output data

|       \_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 |

#### Related

* [Work with durations](/flux/v0/data-types/basic/duration/)

[type-conversions](/flux/v0/tags/type-conversions/)
| _time | tag | _value |
| --- | --- | --- |
| _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 |
| --- | --- | --- |
| _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 |
