# Time calculations in Better logic

**URL:** <https://community.homey.app/t/time-calculations-in-better-logic/11078>\
**Category:** Apps\
**Tags:** app\
**Created:** [March 27, 2019, 8:58am UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078 "2019-03-27T08:58:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikael\_Nystrom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mikael_nystrom/32/8084_2.png) [@Mikael\_Nystrom](https://community.homey.app/u/Mikael_Nystrom)\
**Post date:** [March 27, 2019, 8:58am UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078/1 "2019-03-27T08:58:45Z")

</div>

I’m trying to use the app Better logic to calculate the time between two events in Sun events.  
Is there anyone who know how to calculate the time difference and present it in minutes?

---

<div class="post-metadata">

**Author:** ![neluz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/neluz/32/8853_2.png) [@neluz](https://community.homey.app/u/neluz)\
**Post date:** [March 28, 2019, 9:50am UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078/2 "2019-03-28T09:50:25Z")

</div>

You could make a calculation with the Sun events as variable, but you’ll need to find a way to remove the colon between the numbers. I don’t know if this is possible in a flow or that you may have to script it manually…

---

<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:** [March 28, 2019, 9:59am UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078/3 "2019-03-28T09:59:05Z")

</div>

Use the $timenow$ with a MathJS card and covert the epoch time to mins.

use 2 flows with the

> execute mathJS card

with **`$timenow$`** to a betterlogic variable for **SunEvent1** & **SunEvent2**.  
Then to calculate the difference rounded to the nearest minutes

> **`round(($SunEvent2$ - $SunEvent1$)/60)`**

---

<div class="post-metadata">

**Author:** ![Mikael\_Nystrom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mikael_nystrom/32/8084_2.png) [@Mikael\_Nystrom](https://community.homey.app/u/Mikael_Nystrom)\
**Post date:** [March 29, 2019, 8:26am UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078/4 "2019-03-29T08:26:07Z")

</div>

Thank you, that helped.

My goal was to calculate the time for the so called “golden hour” (app sun events) in the morning and the evening. That time I use to dim som lights to keep them in a comfort level during sun transition from eg bright to dark.

To do that, I use the function “change brightness over time” in Fibaro dimmer 2.  
When I calculated the time for the sun transition from the day before (close enough).  
Then in the evening (at Evening golden hour starts) I turn the lights ON to dim level 100%.  
Then start “change brightness over time” with the time calculated from the MathJS function, and dim the brightness down to 15% (in my case). This creates a perfect brightness of the light from when it’s bright outside, until it’s dark.

Thanks again for the help.

---

<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:** [August 23, 2020, 9:24pm UTC](https://community.homey.app/t/time-calculations-in-better-logic/11078/5 "2020-08-23T21:24:34Z")

</div>

can this be more in detail and better explained? i am looking for sooooo long for calculating with time…
