# Calculating time diffence between 2 events in homey script

**URL:** <https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120>\
**Category:** Questions & Help\
**Created:** [June 4, 2021, 10:42pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120 "2021-06-04T22:42:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIRDY](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/birdy/32/41476_2.png) [@BIRDY](https://community.homey.app/u/BIRDY)\
**Post date:** [June 4, 2021, 10:42pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/1 "2021-06-04T22:42:31Z")

</div>

Hey guys,

I am trying to calculate the daily time difference to determine the rate of light dimming between sunset and dusk.

I have tried a couple of option but all of them seems to have a limitation.

Here are the options I tried and why they failed.

-To calculate the time difference I tried to save the store the time in a variable in better logic app. The problem here is that the time stored in the variable are only the two digits of de 24 hour format.

- I Tried using mathjs in betterlogic by subtracting “dusk-sunset” but I get weird value as output.

So to sum up I calculate time difference because I cant store the data in flow nor script. And I cant mathematically calculate the difference .

Any tips?

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [June 5, 2021, 1:21pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/2 "2021-06-05T13:21:10Z")

</div>

my tip is search this forum for (time) calculation

---

<div class="post-metadata">

**Author:** ![Edgar](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Edgar](https://community.homey.app/u/Edgar)\
**Post date:** [June 6, 2021, 7:59am UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/3 "2021-06-06T07:59:01Z")

</div>

you could make a Homescript and send two parameters, time1 & time2  
convert them to timestamps, substract them, and than you could convert that back to time. or… use my script i posted recently, in Dutch:

> [@HomeyScript seconden naar uren, minuten en seconden](https://community.homey.app/t/homeyscript-seconden-naar-uren-minuten-en-seconden/47643):
>
> Echt super nuttig is dit niet, maar wel leuk voor de mensen die graag dingen bijhouden. Ik heb dit HomeyScript gemaakt om de uitkomst van een stopwatch leesbaarder te maken. Ik heb deze apps daarvoor in gebruik: Met chronograph kun je een stopwatch starten en stoppen. De tijd daartussen wordt opgeslagen in de tag: looptijd (s) Dit is dan opgeslagen in seconden, bijvoorbeeld 42123 seconden. Maar dan weet je nog niet bijster veel. Dus… als je dan het volgende invult bij Als dan zie je de uitk…

```auto
var dateParts = '17-09-2013 10:08'.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/);

console.log(dateParts); // ["17-09-2013 10:08", "17", "09", "2013", "10", "08"]

```

source: [jquery - Converting a datetime string to timestamp in Javascript - Stack Overflow](https://stackoverflow.com/questions/18849351/converting-a-datetime-string-to-timestamp-in-javascript#18849896)

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [October 21, 2021, 1:25pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/4 "2021-10-21T13:25:57Z")

</div>

Check the [Flow Utilities](https://community.homey.app/t/app-pro-flow-utilities/53027) app

Example [[APP][Pro] Flow Utilities - #6 by martijnpoppen](https://community.homey.app/t/app-pro-flow-utilities/53027/6)

---

<div class="post-metadata">

**Author:** ![Berend](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/berend/32/8474_2.png) [@Berend](https://community.homey.app/u/Berend)\
**Post date:** [July 1, 2022, 3:06pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/5 "2022-07-01T15:06:24Z")

</div>

Question for Advanced Flows: Is there an option to temporarily suspend a flow?

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [July 1, 2022, 4:14pm UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/6 "2022-07-01T16:14:54Z")

</div>

It’s a bit Off Topic

But, yes, that can be done the same way as in the OLD flows:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/a/7ad3bbc87accd54c4f14cde203cc605bdafa6345.png)

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/4/3422fa5dbbf41c88064da81d0718f611fb531671.png)

---

<div class="post-metadata">

**Author:** ![Berend](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/berend/32/8474_2.png) [@Berend](https://community.homey.app/u/Berend)\
**Post date:** [July 2, 2022, 10:38am UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/7 "2022-07-02T10:38:41Z")

</div>

I meant a one-card solution

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [July 2, 2022, 11:24am UTC](https://community.homey.app/t/calculating-time-diffence-between-2-events-in-homey-script/48120/8 "2022-07-02T11:24:31Z")

</div>

> [@Berend](#):
>
> one-card solution

The good old disable a flow also works for Advanced Flows!  
Even from a simple flow

 ![Screenshot_20220702-132238_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/0/a02a6e14c106541ab3288587aa61433c11129f28.jpeg)
