Date Time Join for SQL Query

Hello.
I'm trying to combine Date & Time using using ui_text_input and ui_date_picker.
What I'm trying to do is:

  • Input Date and Time to get string like 2020-06-03 12:15:30.000
  • I wold like to use this string to QUERY SQL DataBase.
    I tried this:

if(msg.topic == 'time_start'){
var TimeStart = msg.payload;
}
if(msg.topic == 'date_start'){
var DateStart = msg.payload;
}
if(msg.topic == 'time_end'){
var TimeEnd = msg.payload;
}
if(msg.topic == 'date_end'){
var DateEnd = msg.payload;
}

msg.topic = "Ts: " + TimeStart + " Ds: " + DateStart + " Te: " + TimeEnd + " De: " + DateEnd;

return msg;

But the problem is, that each ui_text_input and ui_date_picker fires an event when it is changed.
Thanks.
BR, Andrej.

You will need to join those two together into one message, which you can do using the Join node. However, how will you know when to run the query?

Hello.
I have solved it using flow.get (Button triggered) / flow.set (UI triggered)

var TimeStart = flow.get("TimeStartSet")||0;
var DateStart = flow.get("DateStartSet")||0;
var TimeEnd = flow.get("TimeEndSet")||0;
var DateEnd = flow.get("DateEndSet")||0;

var DateTimeStart = DateStart + " " + TimeStart;
var DateTimeEnd = DateEnd + " " + TimeEnd;

var dbQuery = "SELECT * FROM Senzorji WHERE [DateTime] >= '" + DateTimeStart + "' AND [DateTime] <= '" + DateTimeEnd + "'"
msg.payload = dbQuery;
return msg;

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.