javascript – How to get data from a especif Time period in InfluxDB Node-RED

I’m trying to read data from InfluxDB v1.x but only in a especific time period, Example:

Get the values of temper01 from 2021-11-09/14:00:00 to 2021-11-10/14:00:00.

i know its possible with this code :

"WHERE time >= '2021-11-09T14:00:00Z' AND time <= '2021-11-10T14:00:00Z'" But i wanna know if it is possible to use a variable instead of the direct timestamp.

i’ve tried this code :

msg.query = "SELECT time , Temper01, Temper02, Temper03 FROM "
+  global.get("ID_device1")
+ " WHERE time >= "
+   msg.payload;
+ " AND time <= '2021-11-18T00:00:00.000Z' " ;

but dosent matter the msg.payload value, it just get data from the very first data stored, and when i try to single quote msg.payload i get the invalid operation: time and *influxql.VarRef are not compatible" error message.

Read more here: Source link