# Passing from and to date and time to http request node

**URL:** <https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [2 January 2023 05:59 UTC](https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045 "2023-01-02T05:59:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jhankhana](https://avatars.discourse-cdn.com/v4/letter/j/35a633/32.png) [@Jhankhana](https://discourse.nodered.org/u/Jhankhana)\
**Post date:** [2 January 2023 05:59 UTC](https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045/1 "2023-01-02T05:59:59Z")

</div>

Hello!  
Need help!

I am trying to read value of current date and time to pass it to http request node.  
Please help me with this.

```auto
[{"id":"ab460fa4.e776e","type":"ui_button","z":"24076265.de751e","name":"","group":"6b69c47b.954aec","order":0,"width":0,"singleBrowser":false,"height":0,"passthru":false,"label":"This MonthHttp","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","powerMode":false,"x":80,"y":680,"wires":[["7d8310a6.c23ae"]]},{"id":"f41c2db2.f9b7f","type":"change","z":"24076265.de751e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":620,"wires":[["5442bc40.8b1334"]]},{"id":"5442bc40.8b1334","type":"function","z":"24076265.de751e","name":"","func":"const date = new Date();\n\nlet day = date.getDate();\nlet dayone = 1;\n//let yesterday = date.getDate() -1 ;\nlet month = date.getMonth() + 1;\nlet year = date.getFullYear();\n\nlet yesterDate = `${year}-${month}-${dayone} 00:00:01`;\nlet currentDate = `${year}-${month}-${day} 23:00:59`;\n//let yesterDate = `2022-11-01 00:00:01`;\n//let currentDate = `2022-11-01 23:00:59`;\nmsg.from=new Date(yesterDate).toISOString();\nmsg.to=new Date(currentDate).toISOString();\nreturn msg;\n\n\n\n\n\n","outputs":"1","language":"javascript","noerr":0,"x":460,"y":620,"wires":[[]],"outputLabels":["From"]},{"id":"53d4fc8.35f1404","type":"debug","z":"24076265.de751e","name":"","active":true,"console":"false","xaxis":"_time","complete":"false","x":610,"y":740,"wires":[]},{"id":"7d8310a6.c23ae","type":"http request","z":"24076265.de751e","name":"","method":"GET","ret":"obj","url":"","timeout":"","mindspherePath":"/api/iottsaggregates/v4/aggregates?assetId=ded1a0bfec43400f970e566f8263c6d3&aspectName=BatchMix&from=2022-12-01T00:00:00.000Z&to=2022-12-29T00:00:00.000Z&intervalUnit=hour&intervalValue=12&select=Agg1_Total_Weight","useMindsphereAuth":true,"isAdmin":false,"secretHeaders":"","x":630,"y":680,"wires":[["53d4fc8.35f1404","16010add.809725","a867b120.a6e2e"]]},{"id":"6b69c47b.954aec","type":"ui_group","z":"","name":"OneMonth","tab":"7ecbab01.42a594","order":1,"disp":true,"width":"20","collapse":false,"_type":"config"},{"id":"7ecbab01.42a594","type":"ui_tab","z":"","name":"DATA","icon":"dashboard","publicAccess":"true","fmAccess":"none","fmAccessType":"private","assetType":"","asset":"","assetName":"","assetText":"","image":"","description":"","hideTitleBar":false,"_type":"config"}]

```

---

<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:** [2 January 2023 10:36 UTC](https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045/2 "2023-01-02T10:36:35Z")

</div>

The flow you show does not appear to be attempting to pass the current date/time to a request node.

I suggest you get an example of what you want running using an inject node to inject the date/time then post that then we will understand better what you are trying to achieve.

**[Edit]** I see that the title of the thread and the description in the first post appear to be in disagreement as to what you want, so even more reason to post a working example.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [2 January 2023 11:12 UTC](https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045/3 "2023-01-02T11:12:50Z")

</div>

You can pass the url to the http node using `msg.url`. So in your function, once you have your dates you can construct the url.  
e.g

```auto
msg.url = `http://example.com?from=${msg.from}&to=${msg.to}` 

```

---

<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:** [3 March 2023 11:12 UTC](https://discourse.nodered.org/t/passing-from-and-to-date-and-time-to-http-request-node/73045/4 "2023-03-03T11:12:54Z")

</div>

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