Reply
Level: Powered On
Posts: 24
Registered: ‎01-26-2017
Accepted Solution

how do you take two 24 hr time values and return a decimal number representing minutes. Example 15:

I have three input boxes Start, End and TotalTime each box would receive 24 hr time values with just hours and minutes.  I would like the TotalTime input box to contain the time difference between Start and End, but, in a decimal format.  As an example the Start time is 15:00 and the End time is 15:20.  The TotalTime input box should calculate to .3 not 00:20.  Do I have to convert text to time the reduce the value to seconds.  An example formula would be great.  Most examples I have found only return the value as minutes and seconds as 00:20.


Accepted Solutions
PowerApps Staff
Posts: 363
Registered: ‎05-04-2016

Re: how do you take two 24 hr time values and return a decimal number representing minutes. Example

[ Edited ]

Try reversing the order in which the parameters are subtracted, then you should get the value you want:

Text(
    (TimeValue(DatacardValue4.Text) - Timevalue(DatacardValue5.Text)) / 1000 / 60 / 60,
    "0.0")

In case, if the value of DatacardValue4.Text is after the value of DatacardValue5.Text, then the value will be positive.

 

If you want the absolute difference between the two values (regardless of which one is the earlier time), you can use the Abs function to get that value:

Text(
    Abs((TimeValue(DatacardValue4.Text) - Timevalue(DatacardValue5.Text)) / 1000 / 60 / 60),
    "0.0")

View solution in original post


All Replies
PowerApps Staff
Posts: 363
Registered: ‎05-04-2016

Re: how do you take two 24 hr time values and return a decimal number representing minutes. Example

If you have the times you want to calculate as text (e.g., in text input controls), then you will need to convert them to time, using the TimeValue function. If you have two time values, you can subtract them, and you will have the result in milliseconds:

ForumPost-001.png

You can also convert the result to have the result in any of the units you want. For the difference in seconds:

ForumPost-002.png

Or in  minutes:

ForumPost-003.png

Or in hours, as I believe your example requires:

ForumPost-004.png

Based on the example in your question, if you want to display that difference with less decimal places, you can use the Text function to format that number as needed:

ForumPost-005.png

Notice that if one of the values is not valid you may end up with an invalid difference, like in the example below

ForumPost-006.png

To prevent that you may want to consider using a control that restricts the values that the user can enter, such as dropdown boxes.

Highlighted
Level: Powered On
Posts: 24
Registered: ‎01-26-2017

Re: how do you take two 24 hr time values and return a decimal number representing minutes. Example

That worked, but, I had to make each of the timevalues negative numbers as Text((-TtimeValue(DatacardValue5.Text) -                    -Timevalue(DatacardValue4.Text)) / 1000 / 60 / 60, "0.0).  What's up with that?

PowerApps Staff
Posts: 363
Registered: ‎05-04-2016

Re: how do you take two 24 hr time values and return a decimal number representing minutes. Example

[ Edited ]

Try reversing the order in which the parameters are subtracted, then you should get the value you want:

Text(
    (TimeValue(DatacardValue4.Text) - Timevalue(DatacardValue5.Text)) / 1000 / 60 / 60,
    "0.0")

In case, if the value of DatacardValue4.Text is after the value of DatacardValue5.Text, then the value will be positive.

 

If you want the absolute difference between the two values (regardless of which one is the earlier time), you can use the Abs function to get that value:

Text(
    Abs((TimeValue(DatacardValue4.Text) - Timevalue(DatacardValue5.Text)) / 1000 / 60 / 60),
    "0.0")