Convert Number Hours to duration

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!

0 25 2,401
25 REPLIES 25

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)

Top Labels in this Space