# How to aggregate by uneven daily hour intervals?

**URL:** <https://community.influxdata.com/t/how-to-aggregate-by-uneven-daily-hour-intervals/57586>\
**Category:** Fluxlang\
**Tags:** windows, aggregate\
**Created:** [July 10, 2025, 7:33am UTC](https://community.influxdata.com/t/how-to-aggregate-by-uneven-daily-hour-intervals/57586 "2025-07-10T07:33:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dewi-ny-je](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/dewi-ny-je/32/5355_2.png) [@dewi-ny-je](https://community.influxdata.com/u/dewi-ny-je)\
**Post date:** [July 10, 2025, 7:33am UTC](https://community.influxdata.com/t/how-to-aggregate-by-uneven-daily-hour-intervals/57586/1 "2025-07-10T07:33:44Z")

</div>

I have a series with energy prices, and I can tell that I have two peaks and two dips in prices each day, and more specifically one pair in the hours 00:00-11:00 and one pair in the range 11:00-23:59.

How can I calculate (for example) the spread within these two, different time windows?

I am aware of the [hourSelection() function | Flux Documentation](https://docs.influxdata.com/flux/v0/stdlib/universe/hourselection/)  
Is it the only way? so something like (untested)

```auto
raw = from(bucket: "energy")
  |> range(start: _start, stop: _stop)
  |> filter(fn: (r) => r._measurement == "€/kWh" and r._field == "current_price")
  |> aggregateWindow(every: 1h, fn: last, createEmpty: false)

morning = raw
  |> hourSelection(start: 0, stop: 11)
  |> aggregateWindow(every: 1d, fn: spread)

afternoon = raw
  |> hourSelection(start: 12, stop: 23)
  |> aggregateWindow(every: 1d, fn: spread)

union(tables: [morning, afternoon])

```

However, the daily `aggregateWindow` will set the timestamp to the beginning of each day, while I would like to keep the beginning of the two time ranges.

How can I do it better?
