# Count function reset daily

**URL:** https://discourse.nodered.org/t/count-function-reset-daily/12538
**Category:** General
**Created:** [24 June 2019 09:20 UTC](https://discourse.nodered.org/t/count-function-reset-daily/12538 "2019-06-24T09:20:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [24 June 2019 09:20 UTC](https://discourse.nodered.org/t/count-function-reset-daily/12538/1 "2019-06-24T09:20:26Z")

</div>

I got the follow function code:

```auto
var count=context.get('count') || 1;
count +=1;
msg.payload = count;
context.set('count', count);
return msg;

```

Now i want it to count the amount daily. So every day it starts at 0. How could i get this?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [24 June 2019 09:25 UTC](https://discourse.nodered.org/t/count-function-reset-daily/12538/2 "2019-06-24T09:25:56Z")

</div>

Hi @Carloj

You could use an Inject node configured to trigger at midnight every day. Use that to trigger a flow that does whatever you want with that day's count and then resets the `count` value in context.

---

<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: [24 June 2019 09:35 UTC](https://discourse.nodered.org/t/count-function-reset-daily/12538/3 "2019-06-24T09:35:02Z")

</div>

As @knolleary said a trigger node but set it's topic to something like "reset" then add code to your function block to reset your counter when msg.topic == "reset"

---

<div class="post-metadata">

### Author: ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)
#### Post date: [24 June 2019 09:55 UTC](https://discourse.nodered.org/t/count-function-reset-daily/12538/4 "2019-06-24T09:55:24Z")

</div>

I understand it, but the device is offline in the night (no power) it's getting power in the morning. Does the trigger still does it job when it starts at like 08:00 in the morning? (it could also start before or after that time.
