Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Feb 18, 2019 07:54 AM
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.
Solved! Go to Solution.
Feb 18, 2019 01:59 PM
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. :grinning_face_with_big_eyes: 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:
Feb 18, 2019 11:45 AM
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.
Here is the link:
Hope it helps.
Mary
Feb 18, 2019 12:31 PM
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?
Feb 18, 2019 12:50 PM
Never mind. I was assuming too much. :slightly_smiling_face: 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…
Feb 18, 2019 01:07 PM
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?
Feb 18, 2019 01:43 PM
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:
Again, I appreciate your help!
Feb 18, 2019 01:59 PM
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. :grinning_face_with_big_eyes: 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:
Feb 18, 2019 02:21 PM
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. :joy:
Feb 18, 2019 02:28 PM
Happy to help! :thumbs_up: 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?
Dec 01, 2021 12:44 PM
I was able to maintain the format of a duration field using
ROUNDDOWN(({Time Available}/3600), 0) & ":" & ROUND(MOD(({Time Available}/60), 60))
Also you can force-to-string in Airtable by adding & “” in the formula. The problem with this approach on a duration field is that it forces the decimal version to string, not the duration.