# Template for a math

**URL:** <https://community.glideapps.com/t/template-for-a-math/40671>\
**Category:** Ask for Help\
**Created:** [April 12, 2022, 11:54pm UTC](https://community.glideapps.com/t/template-for-a-math/40671 "2022-04-12T23:54:11Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 12, 2022, 11:54pm UTC](https://community.glideapps.com/t/template-for-a-math/40671/1 "2022-04-12T23:54:11Z")

</div>

I do a math to determine the time remaining for a scheduled time.  
For example:  
Now is 12/04/22 9:00. The scheduled time is 12/04/22 16:00. The math result is 7:00.  
How do I make a template to be able to write “7h00min” ?  
If it was more than 24hs, for example, 33:20 to write “1d9h20min” ?

---

<div class="post-metadata">

**Author:** ![nathanaelb](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/nathanaelb/32/43079_2.png) [@nathanaelb](https://community.glideapps.com/u/nathanaelb)\
**Post date:** [April 13, 2022, 12:12am UTC](https://community.glideapps.com/t/template-for-a-math/40671/2 "2022-04-13T00:12:51Z")

</div>

You could look into the plugin column called “Format date”, you might be able to achieve this exactly.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 13, 2022, 12:27am UTC](https://community.glideapps.com/t/template-for-a-math/40671/3 "2022-04-13T00:27:26Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/3/c32a0940d424a75444402fffb4add5af60bdc0d1.png)

I use the JavaScript column to do this. I’m abbreviating days as “d”, hours as “h”, mins as “m”.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/0/20540dffaece27547a41f397fed3b9331bad26c2.png)

```auto
if(p1) {

var delta = p1*24*60*60;

// calculate (and subtract) whole days
var days = Math.floor(delta / 86400);
delta -= days * 86400;

// calculate (and subtract) whole hours
var hours = Math.floor(delta / 3600) % 24;
delta -= hours * 3600;

// calculate (and subtract) whole minutes
var minutes = Math.floor(delta / 60) % 60;
delta -= minutes * 60;

// > 1 day

if(days >= 1) {
return days + "d " + hours + "h " + minutes + "m";
}

if(hours >= 1) {
return hours + "h " + minutes + "m";
}

else return minutes + "m";
}

```

Adapted from:

> <https://stackoverflow.com/questions/13903897/javascript-return-number-of-days-hours-minutes-seconds-between-two-dates/13904120#13904120>

IIf you need to adjust it please tell me.

---

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 13, 2022, 12:51am UTC](https://community.glideapps.com/t/template-for-a-math/40671/4 "2022-04-13T00:51:04Z")

</div>

I pasted the code and in p1 I put the math but it returned me 24m when the result would be 24:10, that is, 1d00h10m.  
Where did I go wrong?

---

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 13, 2022, 12:52am UTC](https://community.glideapps.com/t/template-for-a-math/40671/5 "2022-04-13T00:52:15Z")

</div>

How do I fill in the format?

---

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 13, 2022, 12:58am UTC](https://community.glideapps.com/t/template-for-a-math/40671/6 "2022-04-13T00:58:28Z")

</div>

I do the math like this: (d-now)/60  
I don’t know if my mistake would be there

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [April 13, 2022, 2:50am UTC](https://community.glideapps.com/t/template-for-a-math/40671/7 "2022-04-13T02:50:31Z")

</div>

I would try removing the division by 60. The math column will already return a duration formatted in hours, minutes and seconds. Dividing my 60 throws off that result.

The default duration format is new, but the underlying format when calculating the difference between two dates is always in days. Anything to the left of the decimal is days and anything to the right of the decimal is the decimal fraction of a day.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 13, 2022, 3:14am UTC](https://community.glideapps.com/t/template-for-a-math/40671/8 "2022-04-13T03:14:19Z")

</div>

Yeah, my math column was not having the division by 60.

---

<div class="post-metadata">

**Author:** ![agung\_Taufik](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik/32/2589_2.png) [@agung\_Taufik](https://community.glideapps.com/u/agung_Taufik)\
**Post date:** [April 13, 2022, 2:58pm UTC](https://community.glideapps.com/t/template-for-a-math/40671/9 "2022-04-13T14:58:35Z")

</div>

Hi @ThinhDinh  
how to add `formatted` column to screen?  
I use the text component, but it doesn’t appear on the screen

> [@Template for a math](https://community.glideapps.com/t/template-for-a-math/40671/3):
>
> [image] I use the JavaScript column to do this. I’m abbreviating days as “d”, hours as “h”, mins as “m”. if(p1) { var delta = p1\*24\*60\*60; // calculate (and subtract) whole days var days = Math.floor(delta / 86400); delta -= days \* 86400; // calculate (and subtract) whole hours var hours = Math.floor(delta / 3600) % 24; delta -= hours \* 3600; // calculate (and subtract) whole minutes var minutes = Math.floor(delta / 60) % 60; delta -= minutes \* 60; // \> 1 day if(days \>= 1) { re…

---

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 13, 2022, 3:05pm UTC](https://community.glideapps.com/t/template-for-a-math/40671/10 "2022-04-13T15:05:10Z")

</div>

It worked. The error was in my formula.  
Thank you friends for your usual attention.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 14, 2022, 12:01am UTC](https://community.glideapps.com/t/template-for-a-math/40671/11 "2022-04-14T00:01:54Z")

</div>

Can you show me how you’re setting up in screenshots or a video?

---

<div class="post-metadata">

**Author:** ![orci\_astrogildo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/orci_astrogildo/32/33775_2.png) [@orci\_astrogildo](https://community.glideapps.com/u/orci_astrogildo)\
**Post date:** [April 14, 2022, 1:21am UTC](https://community.glideapps.com/t/template-for-a-math/40671/12 "2022-04-14T01:21:25Z")

</div>

The ultimate goal is a message sent to the client/patient via whatsapp on the eve of the appointment.  
Obviously the Template print doesn’t have any formatting yet.  
The goal is to always send a reminder the day before. It needed formatting including days in the situation of Friday remembering Monday events.  
It is only as a result of the help you have given me that I reiterate my gratitude.

 ![1649898320397](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/9/099ad5464f4957e3fe25a7250b1753464262952d.jpeg)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [April 14, 2022, 4:14am UTC](https://community.glideapps.com/t/template-for-a-math/40671/13 "2022-04-14T04:14:54Z")

</div>

Ah thanks, actually I was asking @agung_Taufik about his problem but your explanation is clear about your usage!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [April 15, 2022, 4:15am UTC](https://community.glideapps.com/t/template-for-a-math/40671/14 "2022-04-15T04:15:35Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
