[Resolved]: Getting the underlying date of the OS with exec node

Hi, my lights turns on too late, I checked from the OS side (I run docker), bot the host OS and the docker OS - the timezone is set correctly, but I want to ensure from Node-RED side the time is correct. I use the exec node to run /bin/date - but do not get the a proper answer. I pass char 1 from an init node into exec node, I get back an empty string, and stderr gives /bin/date: invalid date '1'

Any ideas?

[{"id":"cca80ac9.691f58","type":"exec","z":"31180c66.4efe0c","command":"/bin/date","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":340,"y":180,"wires":[["dff643e8.1988c8"],["18a6b660.06aeda"],[]]},{"id":"4884f78f.d816f","type":"inject","z":"31180c66.4efe0c","name":"","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":160,"wires":[["cca80ac9.691f58"]]},{"id":"dff643e8.1988c8","type":"debug","z":"31180c66.4efe0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":160,"wires":[]},{"id":"18a6b660.06aeda","type":"debug","z":"31180c66.4efe0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":590,"y":200,"wires":[]}]

There should be no need to do that, what do you see if you feed an inject providing timestamp into a debug node? Show us exactly what it shows.

msg.payload : number
1544256424326

Sorry, that is not what I meant to ask. Feed the inject into a Function node containing the following and show us what that gives. Also tell us what the current time and time zone are and what the OS shows when you ask for the date, so if in linux use the date command which shows the time and zone.

msg.payload = new Date();
return msg;

As an aside to what Colin is asking, the reason you get this error is because your exec node is appending msg.payload to the command it's running. Untick that box in the exec node and it won't do that.

That worked Mr @knolleary, apologies for bugging you with such trivialities.... !

It would be nice to know the answer to my questions in order to understand why the usual technique does not work.

Apologies Colin, your suuggestion also worked. I had to remove the tick from the exec setup, not to pass through the msg.payload to the exec command, /bin/date - after removing the tick to not passthrough the msg.payload, it worked.

1 Like

I don't understand why you need to do this in the first place. Javascript Date should give you exactly the same time. My question was supposed to help work out why they do not.