# Format duration in minutes as hh:mm

**URL:** <https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430>\
**Category:** Ask for Help\
**Tags:** custom-code\
**Created:** [December 28, 2021, 5:09pm UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430 "2021-12-28T17:09:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [December 28, 2021, 5:09pm UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/1 "2021-12-28T17:09:27Z")

</div>

This is a classic example of where a single experimental code column can save you a _bunch_ of Glide computed columns.

My use case:

I have a column where the value in each row represents a duration in minutes, and I need to format that for display as hh:mm. So, for example…

- 2914 =\> 48:34
- 804 =\> 13:24
- 63 =\> 01:03
- 5 =\> 00:05
- 0 =\> blank

As far as I could tell, none of the plugin columns will handle this. But it looks easy, right?  
Well, the best I could do with Glide computed columns was 6 (!!) columns 🤪  
If anyone - @Jeff_Hager - can improve on that, please let me know. It went like this:

- Column 1: Math column to get the number of whole hours. `Floor(total/60)`
- Column 2: If-then-else column to zero pad the hours…  
– If hours \< 10 then 0, else blank
- Column 3: Math column to get the remaining minutes. `Mod(total,60)`
- Column 4: If-then-else column to zero pad the minutes…  
– If mins \< 10 then 0, else blank
- Column 5: Template column to stitch them together… `{hh-padding}{hh}:{min-padding}{min}`
- Column 6: If-then-else column to deal with the case where the total minutes is zero or empty…  
– If total is empty, then empty  
– If total equals 0, then empty  
– Else template column

Which looked like:

 ![Screen Shot 2021-12-29 at 9.56.29 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/2/0216ee5c2b82cb34cde67ccd20c33bdf93540011.png)

If it only had to be done once, then it’s not so bad. But for my use case I had to do this about 20 times 😱 After the 3rd or 4th time, I’d had enough. So decided to swap those 6 columns out for a single experimental code column…

[https://mcdarren.github.io/glide-mins-to-hhmm](https://mcdarren.github.io/glide-mins-to-hhmm)

```auto
window.function = function (total) {
  if (total.value === undefined) return undefined;
  if (total.value === 0) return undefined;
  var hours = Math.floor(total.value/60);
  var mins = total.value % 60;
  return hours.toString().padStart(2, '0') + ":" + mins.toString().padStart(2, '0');
}

```

Which results in:

 ![Screen Shot 2021-12-29 at 9.57.39 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/5/c/5c0627ebf88641f03c5ad944255196b31203f6ad.png)

So that’s 5x20=100 computed columns saved with just a few lines of javascript 🥳

---

<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:** [December 28, 2021, 5:45pm UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/2 "2021-12-28T17:45:46Z")

</div>

This had been my previous attempt from a while back. Definitely not elegant by any means. Your javascript solution makes way more sense.

> [@Time duration not presenting correctly in glide chart stopwatch](https://community.glideapps.com/t/time-duration-not-presenting-correctly-in-glide-chart/24014/6):
>
> I took it a step further and included Days as well. You can exclude it if you don’t need it. It’s a little involved, but I’ll explain the best I can. Here is my results: First we have the Duration column, which is obvious and what you already have. Next we have the Days column: FLOOR(D)/100 This is simply taking the duration and dropping off the decimals. The division by 100 will be explained later. Next we have the Hours column: FLOOR(MOD(D,1)\*24)/100 Th…

---

<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:** [December 29, 2021, 12:57am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/3 "2021-12-29T00:57:46Z")

</div>

Thanks for sharing!

---

<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:** [December 29, 2021, 1:28am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/4 "2021-12-29T01:28:23Z")

</div>

What an elegant example that shows how a few lines of code can achieve more than no-code. Or maybe the same, but more efficiently.

I still prefer your 6-column no-code solution, simply because it is accessible to me, whereas there is no way I would have been able to reproduce your code. 🙂

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [December 29, 2021, 1:47am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/5 "2021-12-29T01:47:33Z")

</div>

> [@nathanaelb](#):
>
> I still prefer your 6-column no-code solution,

yeah, I get that.  
I’m the same - I always prefer to get things done with standard computed columns where ever I can.  
But creating these same 6 columns over and over and over again was driving me absolute bonkers 🤪

I guess the nice thing about the Experimental Code column is that it becomes an extra bow for your arrow that you can pull out and use when you need it 😉

---

<div class="post-metadata">

**Author:** ![Robert\_Petitto](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/robert_petitto/32/25193_2.png) [@Robert\_Petitto](https://community.glideapps.com/u/Robert_Petitto)\
**Post date:** [December 29, 2021, 2:00am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/6 "2021-12-29T02:00:53Z")

</div>

I agree… Nocode is my preferred solution but sometimes a singular hyperformula or extract matching text plug-in column is more efficient.

---

<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:** [December 29, 2021, 2:14am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/7 "2021-12-29T02:14:11Z")

</div>

> [@Darren\_Murphy](#):
>
> But creating these same 6 columns over and over and over again was driving me absolute bonkers

I agree, in some cases, it’s just more efficient. I have even created a macOS shortcut to access my Github URLs and quickly copy them to the clipboard for the experimental column. I love it.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [December 29, 2021, 2:16am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/8 "2021-12-29T02:16:38Z")

</div>

oooh, please share? 🙂

---

<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:** [December 29, 2021, 2:54am UTC](https://community.glideapps.com/t/format-duration-in-minutes-as-hh-mm/36430/9 "2021-12-29T02:54:49Z")

</div>

[https://www.icloud.com/shortcuts/369ace3b767942a0881c2790855cf928](https://www.icloud.com/shortcuts/369ace3b767942a0881c2790855cf928)

Let me know if you can access this link.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/9/69ef7db3489d0db1c66613fe9afa263366b09b3f.png)

You can substitute your user name in place of mine (thinhdinhlca) and it should work well. I use it to directly grab my Pages URL instead of having to go to the specific repo to get the URL.
