# Calculate with dates

**URL:** <https://community.homey.app/t/calculate-with-dates/107229>\
**Category:** Questions & Help\
**Created:** [March 28, 2024, 1:08am UTC](https://community.homey.app/t/calculate-with-dates/107229 "2024-03-28T01:08:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [March 28, 2024, 1:08am UTC](https://community.homey.app/t/calculate-with-dates/107229/1 "2024-03-28T01:08:43Z")

</div>

is it possible to calculate with time? I want to be able to subtract two different time stamps from each other to get the total amount of minutes difference and use that to create a time offset in a different flow.

I know I can get the time in dd-MM-yyyy HH:mm in better logic, but I cannot subtract the two days, because they are strings and not numbers.

Any tips?

---

<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:** [March 28, 2024, 1:49am UTC](https://community.homey.app/t/calculate-with-dates/107229/2 "2024-03-28T01:49:58Z")

</div>

Indeed you’ll need better logic, it’s very versatile but also quite difficult for me, regarding the ‘formulas’ dev Arie comes up with.  
I’d suggest to ask your Q in the BLL app topic.

I once made an example flow to separate the parts of a timestamp, to calculate with it, maybe it gets you started.

> [@The Flow Exchange(r) - Exchange Your Flows with Others!](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981/72):
>
> Time Calculator With the re-invented Better Logic Library app, we can calculate with time a bit easier without Homeyscript. Apps used: [Better Logic Library](https://homey.app/a/net.i-dev.betterlogic)Other things people need to do to get it working correct? Any questions can be asked in this topic: [https://community.homey.app/t/app-pro-better-logic-library-for-users/71876](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876) TEF: [tef:FLOWS:"H4sIAAAAAAACA7VayXIbyRH9FUbHHGYiVHLtC472ZQ7jk3wjGYxasiiEsd…

---

<div class="post-metadata">

**Author:** ![Patrick\_Van\_Deursen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/patrick_van_deursen/32/56539_2.png) [@Patrick\_Van\_Deursen](https://community.homey.app/u/Patrick_Van_Deursen)\
**Post date:** [March 28, 2024, 9:25am UTC](https://community.homey.app/t/calculate-with-dates/107229/3 "2024-03-28T09:25:57Z")

</div>

Will do that, thanks. and yes for now I did a similar approach as to what you did. calculate everything back to minutes, add everything up, and then have a minute timestap, with which I can calculate. But if I need to do that everywhere, it really inflates the flows…

---

<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:** [March 28, 2024, 8:45pm UTC](https://community.homey.app/t/calculate-with-dates/107229/4 "2024-03-28T20:45:28Z")

</div>

Buckle up 🤪  
Some examples of calculating time, and converting time (from minutes to hours and v.v)

> [@\[APP\]\[Pro\] Better Logic Library - For Users](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/26):
>
> although again it’s a very nice flow from @Peter_Kawa , perhaps here is a somewhat simpler solution. Only issue is, it works with UTC (since Homey base time is always set to UTC/GMT). [image] new Date().setHours(18,0,0,0) - Date.now() \< 5\*60\*1000; This Condition Expression card will return true when the time is less then 5 minutes before 18u00utc.

> [@\[APP\]\[Pro\] Better Logic Library - For Users](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/28):
>
> Well, you can kind off, but not in the easy ‘formatting’ way: because i didn’t find a all-around solutions independend of locale and timezone. date('DATETIME', null, 'en') You will get a tag, you can use the last number if it’s like this. But if you get this, you will probably get the same result as me: So, the complete solution would be: new Date().setHours(18-Number.parseInt(\_.last(date('DATETIME', null, 'en'))),0,0,0) - Date.now() \< 15\*60\*1000; (this is true when less the…

> [@\[APP\]\[Pro\] Better Logic Library - For Users](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/30):
>
> This is guru level crazy_face I only missed the minutes part of the targeted time, a first wild guess seems to work for 'is true when less than 15 minutes before 18.30h: new Date().setHours(18-Number.parseInt(\_.last(date('DATETIME', null, 'en'))),30,0,0) - Date.now() \< 15\*60\*1000;

> [@\[APP\]\[Pro\] Better Logic Library - For Users](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/100):
>
> I share here the power of the BLL card “Set variable to text”.
> 
> ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/0/506c6a2409081288accc267b24b7f3ab5a9aa411.png)
> 
> This means you can add one or more texts and BLL expressions into any text variable, pass the variable to a central flow where you process it with a single BLL card.
> 
> This saves (me) several formatting cards in various flows.
