## General Discussion

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

# 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
Highlighted
PowerApps Staff
Posts: 505
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")```

All Replies
PowerApps Staff
Posts: 505
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:

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

Or in  minutes:

Or in hours, as I believe your example requires:

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:

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

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

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?

Highlighted
PowerApps Staff
Posts: 505
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")```