cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Max1
Advocate IV
Advocate IV

Convert decimals hours to hours and minutes

Hello!

 

I have two inputs in my app, one for hours and one for minutes. A little formular adds the hours to the (minutes/60) and saves it to my database.

 

However now I would like powerapps to read eg "1.5" from the databse and show on screen "1:30" or "1 hour 30 mins".

 

I have managed to get the display result I would like by doing:

 

RoundDown(Value(label_1.Text),0)&" Hrs "&(Value(label_1.Text)-RoundDown(Value(label_1.Text),0))*60&" Mins".

 

However if a user enters a value that they later want to go back and edit, this doesnt work...

 

 

Please can you help me achieve this?

 

Thanks in advance,

 

Max

1 ACCEPTED SOLUTION

Accepted Solutions
nickduxfield
Responsive Resident
Responsive Resident

So your initial fields of Hours and Minutes are not connected to columns. Rather you add data together to place in a single decimal Column. Pulling up the record, you have no way of populating the controls again because they are simply Input controls.

 

Tell me, what database do you have. Are you able to create Columns?

View solution in original post

9 REPLIES 9
Sienna
Memorable Member
Memorable Member

If you got your times only in minutes then

RoundDown(yourMinutes/60,0) & “ hours: “ & Mod(yourMinutes,60) & “minutes”
nickduxfield
Responsive Resident
Responsive Resident

You can create a conversion table in the app as a collection.

Then use a lookup to convert. If users are restricted to 1,1.5,2,2.5... 30min intervals this would be fairly easy.

This way you can write out nice human readable text. or even warnings.

Thank you both for your replies.

 

The main issue I'm facing is that if a user edits a table with a previously saved time, I have no way of back-filling the free text boxes I used to enter the data in the first place.

 

To be clearer, heres the process:

 

User enters hours into one input and minutes into another (accuracy is important). Theres a field called 'label_time' which adds the hours to the (minutes/60). When the form is saved, the decimal hours are written to the database.

 

When the data is loaded from the database, the decimal hours are loaded, but the hours and minutes boxes remain empty as there's no formulas telling them what to do.

 

What should I put in them?

 

Thanks!

nickduxfield
Responsive Resident
Responsive Resident

Im trying to think of the answer, its a good one.

In my mind, all you need is to conver the display of your Data am i correct. The converted display doesnt need to be saved to the database.

 

nickduxfield
Responsive Resident
Responsive Resident

So your initial fields of Hours and Minutes are not connected to columns. Rather you add data together to place in a single decimal Column. Pulling up the record, you have no way of populating the controls again because they are simply Input controls.

 

Tell me, what database do you have. Are you able to create Columns?

View solution in original post

This is correct.

 

The data is being stored in sharepoint tables. 

 

Are you thinking to store the data in its 'hours' and 'minutes' format then recombine at a later date?

nickduxfield
Responsive Resident
Responsive Resident

This is the Crux of your issue.

Go for Hours and Minutes as a number field of 0 decimal places or to your need.

Try creating at Site Column level to improve searchability and re-usablity OOTB these column names are not taken.

 

Then either go for a Calculated column or a Total Column like DecimalTotal.

 

When you do it like this, you can return the Hours and Minutes to the input fields with no problems.

 

I can give you many tips on how to avoid accidents futher if needed.

The Calc column will need to be Round(),) in powerapps.

Thank you for your ideas, I've taken a route hinted at by your first answer.

 

I have created three columns: start_hours; start_mins; start_calc

 

The app inputs and reads from the first two columns and then the third adds the two together (also dividing mins by 60) to get decimal time.

 

Thank you for your help!

KarlHoffmaster
Advocate II
Advocate II

Here is an easy formula if you have a text field with a decimal time value ( 7.75 )

** This assumes your text field will always have a decimal place, so makes sure you format the value in the original field accordingly:    Text(TimeData.Text, "0.00")

------------------------------------------------------

RoundDown(Value(DecimalTimeField.Text),0)
& ":" &
Text(Value(Right(DecimalTimeField.Text, Len(DecimalTimeField.Text) - Find(".", DecimalTimeField.Text) + 1)) * 60, "[$-en-US]00")

----------------------------------------------------------

This will convert the value of "7.75" to:  "7:45".

This will also work with values exceeding 24 hours.

Confluent

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,298)