# Convert Seconds to h:mm in forumla

#1

I’m having trouble with something that seems very simple. I’d like where it says “0.9 available” for it to show that time formatted as “h:mm”, as it does in the “Time Available” field next to it.

Here the formula for the Name field:

Essentially I think I need to convert seconds to hours, minutes and seconds within a formula, but I can’t find a way to do it and feel I’m probably just missing something simple. Thanks so much.

0 Likes

Convert Duration to string
#2

Hi @LouD82

I found some documentation about creating formulas in Airtable.

If you scroll to the bottom of the page there is a link to all the formulas for dates and times.

Hope it helps.

Mary

0 Likes

#3

If I understand you correctly, you want that amount of time rounded to the nearest hour, so that 0:55 (55 minutes) becomes 1:00? Is that correct?

0 Likes

#4

Never mind. I was assuming too much. What you’re seeking is a way to convert 0.9 (in that example) into the time format. However, I’m still not quite sure why you’re rounding the time calculation, but that’s not important.

Off to experiment some more…

0 Likes

#5

Back to questions again. Are you trying to simply echo the “0:55” time in your Name field, so that it looks like:

``````2/18/2019 - 0:55 available
``````

Is that the goal?

0 Likes

#6

Hi Justin, thanks so much for your help. Yep, that’s the goal exactly. I’m rounding the time calculation just for readibility, because otherwise it looks like this:

0 Likes

#7

I tried a bunch of ways to parse/convert the duration back into a datetime item, but it wouldn’t process cleanly, so I ended up force-building an h:mm format by doing the math, which was an interesting exercise by itself. Here’s the full result, which will work for all time durations that I tested (replace TODAY() with your date field):

``````DATETIME_FORMAT(TODAY(), "M/DD/YYYY") & " - " & ROUNDDOWN({Time Available}/3600, 0)
& ":" & ROUND(({Time Available}/60) - (60*ROUNDDOWN({Time Available}/3600, 0)),0)
& " available"
``````

And here’s a screenshot:

1 Like

#8

WOW. Thanks, Justin. Plugged it in and it works flawlessly. It seems so silly that there isn’t a way just to convert or “flatten” the Time Available field to a string, then just plug it in to the formula. Oh well. Your efforts are greatly appreciated, that makes it much easier to schedule my tasks that trying to convert from duration to decimal in my head.

0 Likes

#9

Happy to help! Yes, I agree that having a force-to-string function would be hugely helpful for situations like this. There’s VALUE() for turning strings into numbers, but why not the other way around?

0 Likes