Truncate current time

I wanted to truncate time and for that i wanted to use date.truncate() function of flux. I wanted to use the example given in the page:

import "date"
option now = () => 2021-04-21T20:30:00Z
date.truncate(t: -1h, unit: 1h)
// Should Return 2021-04-21T19:00:00Z

But it is giving error like : “type error @3:17-3:19: expected time but found duration”.
Any solution for this error or any alternative solution for what i want?

@Pratik_Das_Baghel What version of Flux are you using? You can use the runtime.version() function to find out:

import "runtime"

Version is - v0.104.0

@Pratik_Das_Baghel I’m testing the same code against 0.104.0 and it’s behaving as expected. Where are you running this query?

i am running in influxdb ui only. Sorry i made a mistake here, error it was giving everytime was - @0:0-0:0: option “v” depends on option “now”, which is defined in the same package

Gotcha. Yeah, you can’t override now() in the Data Explorer or in dashboards.

Any other way i can obtain results i want?

You could use the Flux REPL, the influx query command, or the api/v2/query endpoint. More information here: Execute queries.

Ok thanks @scott . I have one query can you help - Inputs.kafka_consumer not working. Thanku

Hi Scott,

I want to know my Flux version. Where do I have to execute runtime.version function?


@JMU, yes, you can do it there or through the InfluxDB API /api/v2/query endpoint.


I also tried without he “|>” but the error keeps going

Yeah, runtime.version() doesn’t take any piped-forward data as input, so you shouldn’t include the |>. The fact that the UI injects this function with a pipe-forward operator is a known issue that is now fixed in InfluxDB Cloud and will be fixed in InfluxDB OSS when the next version releases.

It should just be:

import "runtime"