# Nodered function node code

**URL:** https://discourse.nodered.org/t/nodered-function-node-code/11784
**Category:** General
**Created:** [3 June 2019 05:13 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784 "2019-06-03T05:13:34Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sheminasalam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sheminasalam/32/8981_2.png) [@sheminasalam](https://discourse.nodered.org/u/sheminasalam)
#### Post date: [3 June 2019 05:13 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784/1 "2019-06-03T05:13:34Z")

</div>

I am running node red from hassio. I have a sensor in hassio that gives time of some events as payload in the format 2019-06-03T20:38:00. I want to use this sensor for automation but because of this format its not happening. i tried to use node-red-contrib-simpletime, but it gives wrong time. i would like to get advice to execute this. i,e Using the sensor payload which is a time format for calling a service from hassio at that time from the format.

---

<div class="post-metadata">

### Author: ![rei\_vilo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rei_vilo/32/162_2.png) [@rei\_vilo](https://discourse.nodered.org/u/rei_vilo)
#### Post date: [3 June 2019 13:30 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784/2 "2019-06-03T13:30:36Z")

</div>

Have you tried [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment)? It is highly configurable.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 June 2019 16:50 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784/3 "2019-06-03T16:50:13Z")

</div>

Use the JS Date function & you can do what ever you need to...

```auto
var myDate = new Date("2019-06-03T20:38:00")

var y = myDate.getFullYear(); //2019
var h = myDate.getHours();//20

```

[https://www.w3schools.com/js/js\_date\_methods.asp](https://www.w3schools.com/js/js_date_methods.asp)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 June 2019 21:20 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784/5 "2019-06-03T21:20:45Z")

</div>

You need to post more info. What doesn't work? Screen shots? Debug output? Exact format of data you require etc etc.

---

<div class="post-metadata">

### Author: ![sheminasalam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sheminasalam/32/8981_2.png) [@sheminasalam](https://discourse.nodered.org/u/sheminasalam)
#### Post date: [4 June 2019 02:01 UTC](https://discourse.nodered.org/t/nodered-function-node-code/11784/6 "2019-06-04T02:01:15Z")

</div>

Actually it worked, my earlier post was approved late by node red forum..thats why i said it didnt. thanks..now i am able to extract time in the format HH:mm from the input payoad.. But the second part is still confusing. i now have the time extracted, thanks to you all and at this time I have to call a service...mostly like an alarm...that can be set n the flow and not by conventional method of nodered editor..any ideas..?
