# Calculate number of days

**URL:** <https://community.homey.app/t/calculate-number-of-days/9318>\
**Category:** Flows\
**Created:** [February 17, 2019, 6:08pm UTC](https://community.homey.app/t/calculate-number-of-days/9318 "2019-02-17T18:08:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heronimus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/heronimus/32/3564_2.png) [@Heronimus](https://community.homey.app/u/Heronimus)\
**Post date:** [February 17, 2019, 6:08pm UTC](https://community.homey.app/t/calculate-number-of-days/9318/1 "2019-02-17T18:08:52Z")

</div>

I’m planning to create a flow with a day calculation as condition, i.e. when difference between current date - variable\_DateStored1 Greater than 7. How can i calculate this?

The story behind: My battery monitors don’t work reliable, and i want to be sure my sensors work. So when they trigger an event, i will store a timestamp (date). When i see the frontdoorsensor hasn’t triggered an event since a day, thats a reason to check the sensor.

I’ve searched in BetterLogic for date calculations, but am not able to find an answer how to do this in a Homey flow.

Maybe anyone can help?

Kind regards

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [February 17, 2019, 6:20pm UTC](https://community.homey.app/t/calculate-number-of-days/9318/2 "2019-02-17T18:20:11Z")

</div>

> [@Heronimus](#):
>
> When i see the frontdoorsensor hasn’t triggered an event since a day

Is it not an option to use the device trigger “a device hasn’t reported in 1 day” ?

---

<div class="post-metadata">

**Author:** ![Heronimus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/heronimus/32/3564_2.png) [@Heronimus](https://community.homey.app/u/Heronimus)\
**Post date:** [February 18, 2019, 5:53pm UTC](https://community.homey.app/t/calculate-number-of-days/9318/3 "2019-02-18T17:53:26Z")

</div>

Hi RocoDamelshe,  
Thank you for your quick answer. I didn’t know this was a flow trigger. I made a testflow and found that i have to filter the results: too many devices are now reported via this flow. But your idea is worth examining it.

On second hand, i don’t know how to validate the last communication event date & time. But my question stays: can i do day calculations to find out how many days differs from two date variables?

---

<div class="post-metadata">

**Author:** ![FKey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fkey/32/14793_2.png) [@FKey](https://community.homey.app/u/FKey)\
**Post date:** [February 18, 2019, 10:07pm UTC](https://community.homey.app/t/calculate-number-of-days/9318/4 "2019-02-18T22:07:07Z")

</div>

Check out better logic math.js cannot tell you the how but I thinks its possible with that function

---

<div class="post-metadata">

**Author:** ![viix](https://avatars.discourse-cdn.com/v4/letter/v/4af34b/32.png) [@viix](https://community.homey.app/u/viix)\
**Post date:** [February 18, 2019, 10:30pm UTC](https://community.homey.app/t/calculate-number-of-days/9318/5 "2019-02-18T22:30:30Z")

</div>

You can do it with the `$timenow$` function into a better logic variable using the mathjs card.  
Note that it’s in epoch time.

You can create another trigger to check every 3 days with a mathjs expression in the AND slot  
‘If MATHJS expression is TRUE’ with a ‘$timenow$ \> (yourbetterlogicvariable + 259200)

259200 being elapse 3 days in seconds
