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

**URL:** <https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580>\
**Category:** General\
**Created:** [8 December 2018 07:17 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580 "2018-12-08T07:17:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![IoTPlay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotplay/32/40_2.png) [@IoTPlay](https://discourse.nodered.org/u/IoTPlay)\
**Post date:** [8 December 2018 07:17 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/1 "2018-12-08T07:17:36Z")

</div>

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?

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 December 2018 07:56 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/2 "2018-12-08T07:56:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![IoTPlay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotplay/32/40_2.png) [@IoTPlay](https://discourse.nodered.org/u/IoTPlay)\
**Post date:** [8 December 2018 08:08 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/3 "2018-12-08T08:08:08Z")

</div>

msg.payload : number  
1544256424326

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 December 2018 08:35 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/4 "2018-12-08T08:35:45Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [8 December 2018 08:40 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/5 "2018-12-08T08:40:00Z")

</div>

> [@IoTPlay](#):
>
> 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'`

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.

---

<div class="post-metadata">

**Author:** ![IoTPlay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotplay/32/40_2.png) [@IoTPlay](https://discourse.nodered.org/u/IoTPlay)\
**Post date:** [8 December 2018 11:27 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/6 "2018-12-08T11:27:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 December 2018 11:47 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/7 "2018-12-08T11:47:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IoTPlay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iotplay/32/40_2.png) [@IoTPlay](https://discourse.nodered.org/u/IoTPlay)\
**Post date:** [8 December 2018 12:26 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/8 "2018-12-08T12:26:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 December 2018 20:15 UTC](https://discourse.nodered.org/t/resolved-getting-the-underlying-date-of-the-os-with-exec-node/5580/9 "2018-12-08T20:15:39Z")

</div>

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.
