title |
description |
aliases |
menu |
weight |
flux/v0.x/tags |
related |
introduced |
toTime() function |
The `toTime()` function converts all values in the `_value` column to times. |
/influxdb/v2.0/reference/flux/functions/transformations/type-conversions/totime |
/influxdb/v2.0/reference/flux/functions/built-in/transformations/type-conversions/totime/ |
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/totime/ |
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/type-conversions/totime/ |
|
flux_0_x_ref |
name |
parent |
toTime |
universe |
|
|
102 |
type-conversions |
transformations |
|
/flux/v0.x/data-types/basic/time/ |
/flux/v0.x/stdlib/universe/time/ |
|
0.7.0 |
The toTime()
function converts all values in the _value
column to times.
toTime()
{{% note %}}
To convert values in a column other than _value
, define a custom function
patterned after the function definition,
but replace _value
with your desired column.
{{% /note %}}
Supported data types
{{% note %}}
toTime()
treats all numeric input values as nanosecond epoch timestamps.
{{% /note %}}
Parameters
tables
Input data.
Default is piped-forward data (<-
).
Examples
{{% flux/sample-example-intro %}}
Convert an integer value column to a time column
import "sampledata"
data = sampledata.int()
|> map(fn: (r) => ({r with _value: r._value * 1000000000}))
data
|> toTime()
{{< expand-wrapper >}}
{{% expand "View input and output" %}}
{{< flex >}}
{{% flex-content %}}
Input data
_time |
tag |
_value |
2021-01-01T00:00:00Z |
t1 |
-2000000000 |
2021-01-01T00:00:10Z |
t1 |
10000000000 |
2021-01-01T00:00:20Z |
t1 |
7000000000 |
2021-01-01T00:00:30Z |
t1 |
17000000000 |
2021-01-01T00:00:40Z |
t1 |
15000000000 |
2021-01-01T00:00:50Z |
t1 |
4000000000 |
_time |
tag |
_value |
2021-01-01T00:00:00Z |
t2 |
19000000000 |
2021-01-01T00:00:10Z |
t2 |
4000000000 |
2021-01-01T00:00:20Z |
t2 |
-3000000000 |
2021-01-01T00:00:30Z |
t2 |
19000000000 |
2021-01-01T00:00:40Z |
t2 |
13000000000 |
2021-01-01T00:00:50Z |
t2 |
1000000000 |
{{% /flex-content %}}
{{% flex-content %}}
Output data
_time |
tag |
_value |
2021-01-01T00:00:00Z |
t1 |
1969-12-31T23:59:58Z |
2021-01-01T00:00:10Z |
t1 |
1970-01-01T00:00:10Z |
2021-01-01T00:00:20Z |
t1 |
1970-01-01T00:00:07Z |
2021-01-01T00:00:30Z |
t1 |
1970-01-01T00:00:17Z |
2021-01-01T00:00:40Z |
t1 |
1970-01-01T00:00:15Z |
2021-01-01T00:00:50Z |
t1 |
1970-01-01T00:00:04Z |
_time |
tag |
_value |
2021-01-01T00:00:00Z |
t2 |
1970-01-01T00:00:19Z |
2021-01-01T00:00:10Z |
t2 |
1970-01-01T00:00:04Z |
2021-01-01T00:00:20Z |
t2 |
1969-12-31T23:59:57Z |
2021-01-01T00:00:30Z |
t2 |
1970-01-01T00:00:19Z |
2021-01-01T00:00:40Z |
t2 |
1970-01-01T00:00:13Z |
2021-01-01T00:00:50Z |
t2 |
1970-01-01T00:00:01Z |
{{% /flex-content %}} |
|
|
{{< /flex >}} |
|
|
{{% /expand %}} |
|
|
{{< /expand-wrapper >}} |
|
|