I have a decimal column [hours], anywhere from 0 hrs to 5 million hrs and I want to return a datetime, taking NOW() - [hours]
[hours] is currently decimal type with two digits… 1.73 hours…
Help, my brain is fried!
NOW() - ([hours] / 24)
No this is wrong…
But it feels so right!
I hate date and time math…
Same
Make an intermediate VC, Duration type. Build the Duration string manually from the decimal value
“00” & floor([hours]) & “:” & ([hours] - (floor([hours])) * 100) & “:00”
Then do NOW() - [intermediate vc]
??
Thus my suggestion of a DURATION() expression in:
That would work, yes; but what I’m trying to do is get away from having to create specific temporary variable holding columns… ones that are only used in a very specific situation.
I’d like to get rid of those and instead cascade all of those into a single field that I can then pull the data out and force it into a specific type. There is only ever one temporary variable present at a time, it’s just that they are of different types and in order to work with them certain concessions must be made.
if I have a single temporary variable, but that temporary variable could take the form of a number, a price, a decimal, a duration; in order for me to work with any of these, they each used to require their own individual column type - but since we can convert things to a specific type, I can throw them all inside a single text column and then format that data whenever I use it using a type forcing formula.
Well, that was harder than it needed to be… here is where I ended up
NOW()-
((TIME(
CONCATENATE(
MOD(FLOOR([target_drtn_hr_cnt]), 24),
“:”,
(MOD(((60 * 60) * [target_drtn_hr_cnt]), (60 * 60)) / 60),
“:”,
MOD(((60 * 60) * [target_drtn_hr_cnt]), 60)
)
)
- “00:00:00”
) + (FLOOR([target_drtn_hr_cnt] / 24) * 24))
It’s in this help article: DOH
Oohhh, TIME() !!
I guess that’s my DURATION() expression I was asking for?
That’s what one would call, “the long way around the barn”
a beefy expression if I ever saw one
Open to ideas lol
Honestly, I think that’s the best one can do given the tools available… Times/dates are literally the worst.
One could say Time has always been the enemy
Yeah, it really is painful…
You’re welcome.
I love seeing how you’ve gotten in and are helping create value…
It would be really cool if there was an arena on help.appsheet.com that had just a ton of examples…
It’s always interesting to see the problems people have, and how they solve them.
A good idea, but the curation effort to keep it concise would be substantial.
Unless the help can be meta tagged… Then yes…
Is this formula honestly the best/only method to make durations out of numbers in hrs
As far as I know… LOL
The best way that i’ve thought to correct this is to allow a Unit Of Measure to be applied to number/decimal… (That would also let you see it as a label in certain places of the app…) or an expression with arguments for hours, minutes, seconds, days, weeks, months, years, etc… like DURATION([column_name], “Hours”)
If I don’t have decimal is there a better way? If it’s only whole number hrs?
I’m not 100% but I think you can just *1.0 and it’ll force it to decimal for calcs…
Affirmative
Thanks @MultiTech_Visions you’re one of my favorite Appsheeple… Come on, that’s pretty good slang…
I mean can I avoid the *60 portions because I will never have part of a number. Numbers auto convert to decimal when doing math I believe.
If you’re never going to have a decimal portion of the hours, and you literally just need to “inject” the hours into the duration, you could do it this way:
NOW() - concatenate(left(“000” & [Hours], 3), “:00:00”)
I’m thinking that would work (but I haven’t tested that)
User | Count |
---|---|
61 | |
25 | |
14 | |
11 | |
6 |