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"
runtime.version()

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