Documentation

boundaries.week() function

boundaries.week() returns a record with start and stop boundary timestamps of the current week. By default, weeks start on Monday.

Function type signature
(?start_sunday: bool, ?week_offset: int) => {stop: time, start: time}
  • Copy
  • Fill window

For more information, see Function type signatures.

Parameters

start_sunday

Indicate if the week starts on Sunday. Default is false.

When set to false, the week starts on Monday.

week_offset

Number of weeks to offset from the current week. Default is 0.

Use a negative offset to return boundaries from previous weeks. Use a positive offset to return boundaries for future weeks.

Examples

Return start and stop timestamps of the current week starting on Monday

import "date/boundaries"

option now = () => 2022-05-10T00:00:00.00001Z

boundaries.week(

)// Returns {start: 2022-05-09T00:00:00.000000000Z, stop: 2022-05-16T00:00:00.000000000Z}
  • Copy
  • Fill window

Return start and stop timestamps of the current week starting on Sunday

import "date/boundaries"

option now = () => 2022-05-10T10:10:00Z

boundaries.week(
    start_sunday: true,
)// Returns {start: 2022-05-08T00:00:00.000000000Z, stop: 2022-05-14T00:00:00.000000000Z}
  • Copy
  • Fill window

Query data from the current week

import "date/boundaries"

thisWeek = boundaries.week()

from(bucket: "example-bucket")
    |> range(start: thisWeek.start, stop: thisWeek.stop)
  • Copy
  • Fill window

Query data from last week

import "date/boundaries"

lastWeek = boundaries.week(week_offset: -1)

from(bucket: "example-bucket")
    |> range(start: lastWeek.start, stop: lastWeek.stop)
  • Copy
  • Fill window

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: