# Problems with hour

**URL:** <https://discourse.nodered.org/t/problems-with-hour/31485>\
**Category:** General\
**Created:** [12 August 2020 17:03 UTC](https://discourse.nodered.org/t/problems-with-hour/31485 "2020-08-12T17:03:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [12 August 2020 17:03 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/1 "2020-08-12T17:03:05Z")

</div>

Hi guys I have this flow but I'm trying to get my current hour but is not even close I don't know what is happening  
 ![Sin título](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d39d561da4bcfd94cc265cec66a1fd121fa3cb09.png)

```auto
[{"id":"5f2dfd9c.f03124","type":"function","z":"8b253657.5d90d8","name":"","func":"global.set('valueone',msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":232,"wires":[["43dda46c.a02cac"]]},{"id":"43dda46c.a02cac","type":"debug","z":"8b253657.5d90d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":232,"wires":[]},{"id":"bc2e421c.1ea6d","type":"inject","z":"8b253657.5d90d8","name":"messagenumerone","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()\t","payloadType":"jsonata","x":180,"y":232,"wires":[["5f2dfd9c.f03124"]]},{"id":"29a17fb.d08298","type":"inject","z":"8b253657.5d90d8","name":"messagenumertwo","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()","payloadType":"jsonata","x":180,"y":280,"wires":[["76094289.9729cc"]]},{"id":"83e2c27b.29aec","type":"debug","z":"8b253657.5d90d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":534,"y":280,"wires":[]},{"id":"76094289.9729cc","type":"function","z":"8b253657.5d90d8","name":"","func":"var getvalueone = global.get(\"valueone\");\nvar getvaluetwo = msg.payload;\nvar nd = new Date().toISOString().split(\"T\");\nvar d = nd[0]\nvar t = nd[1].substring(0,8)\nvar dt = d+\" \"+t\nreturn {payload:{\"time\":dt,\"value2\":getvaluetwo,\"value1\":getvalueone} };","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":280,"wires":[["83e2c27b.29aec"]]}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 August 2020 17:22 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/2 "2020-08-12T17:22:49Z")

</div>

Ok this in context of your previous flow correct ?

What timezone are you in ?

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [12 August 2020 17:24 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/3 "2020-08-12T17:24:24Z")

</div>

yeah this of my previous flow my timezone is in mexico it will be UTC -5

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 August 2020 17:55 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/4 "2020-08-12T17:55:48Z")

</div>

Try this flow instead. Date/time are not always friendly to deal with, here I used jsonata in a change node instead as it has built-in timezones makes it a lot easier. Not need for function nodes either

```auto
[{"id":"9f9dbced.7ee338","type":"debug","z":"ea67f3fb.0745f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":240,"wires":[]},{"id":"c24f1260.e9847","type":"inject","z":"ea67f3fb.0745f","name":"messagenumerone","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()\t","payloadType":"jsonata","x":268,"y":240,"wires":[["beaddbe2.c36c3"]]},{"id":"7473052f.0b625c","type":"inject","z":"ea67f3fb.0745f","name":"messagenumertwo","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$random()","payloadType":"jsonata","x":268,"y":288,"wires":[["47b6ad5c.3c2bdc"]]},{"id":"c8a4a756.b2b268","type":"debug","z":"ea67f3fb.0745f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":288,"wires":[]},{"id":"47b6ad5c.3c2bdc","type":"change","z":"ea67f3fb.0745f","name":"","rules":[{"t":"set","p":"value2","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.time","pt":"msg","to":"$moment().tz('America/Mexico_City').format(\"YYYY-MM-DD hh:mm:ss\")\t","tot":"jsonata"},{"t":"set","p":"payload.value1","pt":"msg","to":"value1","tot":"global"},{"t":"move","p":"value2","pt":"msg","to":"payload.value2","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":488,"y":288,"wires":[["c8a4a756.b2b268"]]},{"id":"beaddbe2.c36c3","type":"change","z":"ea67f3fb.0745f","name":"","rules":[{"t":"set","p":"value1","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"value1","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":488,"y":240,"wires":[["9f9dbced.7ee338"]]}]

```

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [12 August 2020 18:06 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/5 "2020-08-12T18:06:39Z")

</div>

Alright actually I haven't seen a flow like that to work with Date/time and yeah is not really friendly to work with that. Thanks

---

<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:** [12 August 2020 19:26 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/6 "2020-08-12T19:26:54Z")

</div>

Alternatively you could use node-red-contrib-simpletime.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 August 2020 19:27 UTC](https://discourse.nodered.org/t/problems-with-hour/31485/7 "2020-08-26T19:27:03Z")

</div>

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