Hi,
I have a query as mentioned below
from(bucket: “bucket1”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “measurement1”)
|> filter(fn: (r) => r[“tag”] == “tag1”)
I am getting the output with time format as 2022-05-01 16:23:30.905
I want to remove the last .905 from the time zone and display 2022-05-01 16:23:30.
How to do it
|> truncateTimeColumn(unit: 1s)
That if you want to work with time, but if you need it for something diferent than time you could duplicate column _time, convert to string and trim based on num of characters with substring()
When I am using the above truncate
from(bucket: “bucket1”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “measurement1”)
|> filter(fn: (r) => r[“tag”] == “tag1”)
|> truncateTimeColumn(unit: 1s)
I am getting the output with time format as 2022-05-01 16:23:30.000
I want to remove the last .000 from the time zone and display 2022-05-01 16:23:30.
Seriously man, I already gave you the solution, by this time you should be able to figure it out by yourself.
BRB with code
Dont forget import “string” at the top.
And keep in mind that this is not a time format this is a string conversion of the _time colum, I am not sure why you need this specific format but here we go:
|> map(fn: (r) => ({ r with timestring: strings.substring(v: strings.replaceAll(v: string( v: r._time ), t: "T", u: " ") , start: 0, end: 20)}))
Also keep in mind the time zone, date on influxDB is stored as UTC, so the string will be in UTC, not Local time