Hello to All,
I dad issues when trying to display information from sqlite to a ui template as a table and one of the columns needed to be a readable timestamp. Because I saved the date with a timestamp inject or Date.now to the database it was in UNIX format (I needed 1 hour to find that the format is called UNIX format
). I managed to transform the sqlite output data TIMESTAMP with a function node and the below code. The sql date column is called TIMESTAMP and I have many recoreds (around 100) and because of this I use msg.payload[i].TIMESTAMP to match it and change it before providing the msg.payload to the ui template. I used the example below and now with this code it works nice and hope this code helps someone. I first tried saving the date in the correct format with th DATE/TIME formater node in the sqlite but it did not accept this and after this I tried to add to the UI Template but it uses angular js and for some reason it did not work, so I think this is a nice option to change it with a func node and then provide the data to the ui template to create a html table with the values.
var i;
for (i = 0; i <msg.payload.length; i++) {
unix_time = msg.payload[i].TIMESTAMP;
var a = new Date(unix_time * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
msg.payload[i].TIMESTAMP = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
}
return msg;