Timeshift() does not shift correctly (or does it)?

Disclaimer: Douple post because of no answer in the InfluxDB 2 forum

Hi All,

I have the following data:


Now I want to shift that one month backwards, meaning that it starts January 1st, and then February 1st, Match 1st and so on. But if I now use:

|> timeShift(duration: -1mo)

I get the following result:


which looks like timeshift just substracts a fixed amount of days instead of a correct calendar month.
Is this the expected behaviour? If yes, what can I do the get the desired result?

Best regards,

timeShift() adds a fixed duration to time columns.

For the above scenario, you can use date.sub() to subtract a duration from a time value.

import "date"

date.sub(d: 1mo, from: 2021-03-01T00:00:00Z)
// Returns 2021-02-01T00:00:00.000000000Z

Ah thanks, this works indeed, using the map() function:

|> map(fn: (r) => ({r with _time: date.sub(d: 1mo, from: r._time)}))

Nevertheless, I think timeShift should not use fixed duration because as we all know, this duration changes over the year

1 Like