# Help me to create day counter

**URL:** <https://discourse.nodered.org/t/help-me-to-create-day-counter/67997>\
**Category:** General\
**Created:** [20 September 2022 23:10 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997 "2022-09-20T23:10:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [20 September 2022 23:10 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997/1 "2022-09-20T23:10:23Z")

</div>

Hi i want to create a day counter. from today - the day i wanted(like 01/12/2022) and i want the output to be in days( like "24" days).  
can someone help me do this?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [20 September 2022 23:44 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997/2 "2022-09-20T23:44:35Z")

</div>

Hi boo,

Did you try anything already ? Have you tried searching for help ?  
It's always better to have a go yourself then ask for help if you get stuck 🤪

Google for JS date functions or **W3Schools** is a good site to learn from.

I did a quick google for **js countdown to date** and there are lots of results, This one could be adapted to do what you want -  
[https://www.w3schools.com/howto/howto\_js\_countdown.asp](https://www.w3schools.com/howto/howto_js_countdown.asp)

---

<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:** [21 September 2022 08:47 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997/3 "2022-09-21T08:47:46Z")

</div>

You can use $moment() in a change node with JSONata  
e.g.

```auto
[{"id":"1e050571.4f7a43","type":"inject","z":"9790f611.6dd06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"01/12/2022","payloadType":"str","x":150,"y":780,"wires":[["112a6b2c.52dded"]]},{"id":"112a6b2c.52dded","type":"change","z":"9790f611.6dd06","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$string($ceil($moment($$.payload, [\"DD-MM-YYYY\", \"YYYY-MM-DD\"]).diff($moment(), 'hours') / 24)) & \" Days till \" & $$.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":780,"wires":[["8c51a7f9.1e84e8"]]},{"id":"8c51a7f9.1e84e8","type":"debug","z":"9790f611.6dd06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":780,"wires":[]}]

```

Expression

```auto
$string(
    $ceil(
        $moment($$.payload,["DD-MM-YYYY", "YYYY-MM-DD"]).diff($moment(), 'hours')
        / 24
    )
) & " Days till " & $$.payload

```

---

<div class="post-metadata">

**Author:** ![boo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/boo/32/67804_2.png) [@boo](https://discourse.nodered.org/u/boo)\
**Post date:** [21 September 2022 11:03 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997/4 "2022-09-21T11:03:22Z")

</div>

thanks both works 💗

---

<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:** [5 October 2022 11:03 UTC](https://discourse.nodered.org/t/help-me-to-create-day-counter/67997/5 "2022-10-05T11:03:34Z")

</div>

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