[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?



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



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.