cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Responsive Resident
Responsive Resident

Re: Convert decimals hours to hours and minutes

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

8 REPLIES 8
Highlighted
Memorable Member
Memorable Member

Re: Convert decimals hours to hours and minutes

If you got your times only in minutes then

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

Re: Convert decimals hours to hours and minutes

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.

Highlighted
Advocate IV
Advocate IV

Re: Convert decimals hours to hours and minutes

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!

Highlighted
Responsive Resident
Responsive Resident

Re: Convert decimals hours to hours and minutes

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.

 

Highlighted
Responsive Resident
Responsive Resident

Re: Convert decimals hours to hours and minutes

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

Highlighted
Advocate IV
Advocate IV

Re: Convert decimals hours to hours and minutes

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?

Highlighted
Responsive Resident
Responsive Resident

Re: Convert decimals hours to hours and minutes

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.

Highlighted
Advocate IV
Advocate IV

Re: Convert decimals hours to hours and minutes

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!

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (11,377)