# Action between two time strings

**URL:** <https://discourse.nodered.org/t/action-between-two-time-strings/70067>\
**Category:** General\
**Created:** [3 November 2022 21:13 UTC](https://discourse.nodered.org/t/action-between-two-time-strings/70067 "2022-11-03T21:13:45Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [4 November 2022 07:42 UTC](https://discourse.nodered.org/t/action-between-two-time-strings/70067/3 "2022-11-04T07:42:45Z")

</div>

@wofforduk welcome to the forum.

First your flow wouldn't import so I edited it so it would (see note at end of this post)

Looking at the data in the `inject` node, it looks like your python program is returning a json string. If you push it thru a `json` object, this is what you get:  
 ![Screen Shot 2022-11-04 at 3.17.37 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b06ac751f97433dae69bc6a2a22b1644ee37ca69.png)  
Notice all the dates are strings. To compare them you could use  
`x = Date(string_date)`  
here is a `function` node that will change all the date strings in your object to milliseconds.

```auto
let nextRunStart = msg.payload.nextRunStart
let nextRunEnd = msg.payload.nextRunEnd
let updatedAt = msg.payload.updatedAt

let startDt = msg.payload.timesObj[0].startDt
let endDt = msg.payload.timesObj[0].endDt

msg.payload.nextRunStart = Date.parse(nextRunStart)
msg.payload.nextRunEnd = Date.parse(nextRunEnd)
msg.payload.updatedAt = Date.parse(updatedAt)

msg.payload.timesObj[0].startDt = Date.parse(startDt)
msg.payload.timesObj[0].endDt = Date.parse(endDt)

return msg;

```

or you might want to edit your python code to return the values as time to eliminate the need for the conversion in your flow.

hopefully this will help you deal with the rest of your flow.

```auto
[{"id":"d92e6fbc84e11bd3","type":"inject","z":"14aabb1a.e5d4a5","name":"Sample returned string from script","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"nextRunStart\": \"2022-11-03 23:30:00+00:00\", \"nextRunEnd\": \"2022-11-04 06:30:00+00:00\", \"timesObj\": [{ \"startDt\": \"2022-11-03 23:30:00+00:00\", \"endDt\": \"2022-11-04 06:30:00+00:00\" }], \"updatedAt\": \"2022-11-03 21:06:45.308625+00:00\" }","payloadType":"str","x":380,"y":80,"wires":[["b746e564625d7942","601afc07663aa8ef","3f276b67bf9c7e76"]]},{"id":"601afc07663aa8ef","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 30","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":120,"wires":[]},{"id":"31fffee69014e9dc","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 31","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":120,"wires":[]},{"id":"cd8bc32f1068860e","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 33","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":80,"wires":[]},{"id":"3f276b67bf9c7e76","type":"json","z":"14aabb1a.e5d4a5","name":"","property":"payload","action":"","pretty":false,"x":610,"y":80,"wires":[["31fffee69014e9dc","3a3c7f285f6e9793"]]},{"id":"3a3c7f285f6e9793","type":"function","z":"14aabb1a.e5d4a5","name":"function 3","func":"let nextRunStart = msg.payload.nextRunStart\nlet nextRunEnd = msg.payload.nextRunEnd\nlet updatedAt = msg.payload.updatedAt\n\nlet startDt = msg.payload.timesObj[0].startDt\nlet endDt = msg.payload.timesObj[0].endDt\n\n\nmsg.payload.nextRunStart = Date.parse(nextRunStart)\nmsg.payload.nextRunEnd = Date.parse(nextRunEnd)\nmsg.payload.updatedAt = Date.parse(updatedAt)\n\nmsg.payload.timesObj[0].startDt = Date.parse(startDt)\nmsg.payload.timesObj[0].endDt = Date.parse(endDt)\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":80,"wires":[["cd8bc32f1068860e"]]}]

```

  

* * *
  

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

_[View the full topic](https://discourse.nodered.org/t/action-between-two-time-strings/70067)._
