docs-v2/content/flux/v0.x/stdlib/universe/hourselection.md

2.4 KiB

title description aliases menu weight flux/v0.x/tags introduced
hourSelection() function The `hourSelection()` function retains all rows with time values in a specified hour range. Hours are specified in military time.
/influxdb/v2.0/reference/flux/functions/transformations/hourselection
/influxdb/v2.0/reference/flux/functions/built-in/transformations/hourselection/
/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/hourselection/
/influxdb/cloud/reference/flux/stdlib/built-in/transformations/hourselection/
flux_0_x_ref
name parent
hourSelection universe
102
transformations
date/time
0.39.0

The hourSelection() function retains all rows with time values in a specified hour range.

hourSelection(
    start: 9,
    stop: 17,
    timeColumn: "_time",
)

Parameters

start

({{< req >}}) The first hour of the hour range (inclusive). Hours range from [0-23].

stop

({{< req >}}) The last hour of the hour range (inclusive). Hours range from [0-23].

timeColumn

The column that contains the time value. Default is "_time".

tables

Input data. Default is piped-forward data (<-).

Examples

The following example uses generate.from() to generate sample data and show how covariance() transforms data.

Filter by business hours

import "generate"

data = generate.from(
    count: 8,
    fn: (n) => n * n,
    start: 2021-01-01T00:00:00Z,
    stop: 2021-01-02T00:00:00Z,
)
  
data 
    |> hourSelection(start: 9, stop: 17)

{{< expand-wrapper >}} {{% expand "View input and output" %}} {{< flex >}} {{% flex-content %}}

Input data
_time _value
2021-01-01T00:00:00Z 0
2021-01-01T03:00:00Z 1
2021-01-01T06:00:00Z 4
2021-01-01T09:00:00Z 9
2021-01-01T12:00:00Z 16
2021-01-01T15:00:00Z 25
2021-01-01T18:00:00Z 36
2021-01-01T21:00:00Z 49

{{% /flex-content %}} {{% flex-content %}}

Output data
_time _value
2021-01-01T09:00:00Z 9
2021-01-01T12:00:00Z 16
2021-01-01T15:00:00Z 25

{{% /flex-content %}} {{< /flex >}} {{% /expand %}} {{< /expand-wrapper >}}