cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JayanthanJ
Helper I
Helper I

Calculate hours based on start created date and closure date

Hi,

    I have been trying to customize a SP list using power apps. In that, I want to find the aging between start and end date in terms of days and hours. I used the below formula for aging in days.

If(IsBlank(DateValue3),DateDiff(DateValue(DateValue2),Today()),DateDiff(DateValue(DateValue2),DateValue3)) where datevalue2 is created date and datevalue3 is closure date. 

 

I tried using the same formula for hours but it is not working. Could someone please tell me what formula to use?

 

PS: The dates are in the format of Date and time formats as shown in the below screenshot

JayanthanJ_0-1670238686006.png

 

 

1 REPLY 1
iAm_ManCat
Super User
Super User

Hi @JayanthanJ 

 

This formula gets you a label which shows the difference between two times and displays in hours, you could modify that for your needs.

I've attached a sample app to show you how this would work for both days and hours.

 

If(
    IsBlank(DateValue1.SelectedDate),
    DateDiff(
        DateTime(
            Year(DateValue2.SelectedDate),
            Month(DateValue2.SelectedDate),
            Day(DateValue2.SelectedDate),
            Hour(
                DateAdd(
                    Today(),
                    HourValue2.Selected.Value,
                    Hours
                )
            ),
            Minute(
                DateAdd(
                    Today(),
                    MinuteValue2.Selected.Value,
                    Minutes
                )
            ),
            0
        ),
        DateTime(Year(Today()), Month(Today()),Day(Today()),Hour(Now()),Minute(Now()),0),
        Hours
    ),
    //Difference between today and today but hours are different based on selection
    DateDiff(
        DateTime(
            Year(Today()),
            Month(Today()),
            Day(Today()),
            Hour(
                DateAdd(
                    Today(),
                    HourValue1.Selected.Value,
                    Hours
                )
            ),
            Minute(
                DateAdd(
                    Today(),
                    MinuteValue1.Selected.Value,
                    Minutes
                )
            ),
            0
        ),
        DateTime(
            Year(Today()),
            Month(Today()),
            Day(Today()),
            Hour(
                DateAdd(
                    Today(),
                    HourValue2.Selected.Value,
                    Hours
                )
            ),
            Minute(
                DateAdd(
                    Today(),
                    MinuteValue2.Selected.Value,
                    Minutes
                )
            ),
            0
        ),
        Hours
    )
) & " Hours"

 

Cheers,

Sancho

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,829)