cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
beatrizmoura26
Helper II
Helper II

I need help with a calculation of hours in power apps.

Good afternoon guys, I need help with a calculation of hours in power apps.

I have 2 date and time information in the system, one I got from an external database and the other I created a variable and added the NOW () function. I need to do a calculation to know how many hours there is difference between these dates considering the month, the year and the hours. Someone help me?

What I already did was this:

"Invoice Hours" & "" & DateDiff (Today (); DateValue (Var_hr_canc); Hours) & "" & "Hrs"

So this function does not return the right amount of hours. If it is less than 24 hours she does not show me only stays 24 hours

1 ACCEPTED SOLUTION

Accepted Solutions

Hi@beatrizmoura26,

Could you please share a bit more about your scenario:

  1. Is there a DatePicker with Time and Minute Dropdown for Var_hr_canc or not?
  2. How you set you variable Var_hr_canc, share your formula

Do you want to calculate the time between the Today() and another date within the Var_hr_canc?

The formula you provided is obviously two date values rather than date-time values, it will always display 24 if it is less than 24 hours.

If you want to display hour difference between two dates, there is no way to achieve this except that there is Time and Minute Dropdown as below:

090101.png

I have a test on my side, please take a try as below.

Add a Button and set the OnSelect property as below:

 

Set(
    Var_hr_canc,
    DatePicker2.SelectedDate + Time(
        Value(Dropdown2.Selected.Value),
        Value(Dropdown1.Selected.Value),
        0
    )
)

 

Note: Dropdown2 represents HourSelect control, Dropdown1 represents MinuteSelect control.

Set the Text property of the Label as below:

 

"Invoice Hours" & "" & DateDiff(
    Now(),
    Var_hr_canc,
    Hours
) & "" & "Hrs"

 

090102.png

Best Regards,

Qi

 

 

View solution in original post

3 REPLIES 3
shinichi_kawara
Advocate I
Advocate I

Hi beatrizmoura26,

Try the following:

"Invoice Hours" & "" & DateDiff(DateTimeValue(Today()); DateTimeValue(Var_hr_canc); Hours) & "" & "Hrs"

 

@shinichi_kawara 


Did not work!

Error: Invalid argument (date). Expecting a TEXT value, instead.

beatrizmoura26_0-1598644086713.png

 

Hi@beatrizmoura26,

Could you please share a bit more about your scenario:

  1. Is there a DatePicker with Time and Minute Dropdown for Var_hr_canc or not?
  2. How you set you variable Var_hr_canc, share your formula

Do you want to calculate the time between the Today() and another date within the Var_hr_canc?

The formula you provided is obviously two date values rather than date-time values, it will always display 24 if it is less than 24 hours.

If you want to display hour difference between two dates, there is no way to achieve this except that there is Time and Minute Dropdown as below:

090101.png

I have a test on my side, please take a try as below.

Add a Button and set the OnSelect property as below:

 

Set(
    Var_hr_canc,
    DatePicker2.SelectedDate + Time(
        Value(Dropdown2.Selected.Value),
        Value(Dropdown1.Selected.Value),
        0
    )
)

 

Note: Dropdown2 represents HourSelect control, Dropdown1 represents MinuteSelect control.

Set the Text property of the Label as below:

 

"Invoice Hours" & "" & DateDiff(
    Now(),
    Var_hr_canc,
    Hours
) & "" & "Hrs"

 

090102.png

Best Regards,

Qi

 

 

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (66,145)