web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to calculate worki...
Power Apps
Answered

How to calculate working hrs between two date and time fields in PowerApp?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee


Our working hrs are from 8 am to 5 pm. The task assigned date is 21/07/2020 11:30 am and the task completed date is 24/07/2020 10:00 am. I captured assigned and completed dates in separate text fields.

DateDiff(DateTimeValue(AssignedDateTime.Text),DateTimeValue(CompletedDateTime.Text),Hours)

By the above formula, I can find the total hours between two dates and times. But I want to exclude non-working hours. How to achieve this?

Categories:
I have the same question (0)
  • KrishnaV Profile Picture
    5,023 on at

    Hi @Anonymous 

     

    Please find the below video to find the business days and then you can multiple with 8.

    https://youtu.be/QVvhDe6puq0

     

    This video will walk you through step by step a big shoutout to @RezaDorrani a reputed Microsoft Power Platform MVP for this video.

     

    I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

    Regards,
    Krishna
    If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.

     

     

  • samtim Profile Picture
    8 on at

    Hi @KrishnaV ,

     

    Thanks for the response. The video you posted is just excluding holidays and weekends but in my case, I want to exclude non-working hours as well.

  • Verified answer
    v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous ,

    Do you want to only calculate working hours between two date time?
    Could you tell me whether you want to exclude holidays and weekends?

    If you do not want to exclude holidays and weekends, things will be easier.

    You just need to count the start day's working time, end day's working time ,Interval days' working time and add them up.

    I've made a similar test for your reference:

    1)use these controls to choose date time: DatePicker1,Dropdown2,Dropdown3,DatePicker2,Dropdown2_1,Dropdown3_1

    2)set Dropdown2's Items:

    [8,9,10,11,12,13,14,15,16,17]

    Dropdown3's Items:

    [0,1,2,3,4,5,6,....,59]

    Dropdown2_1,Dropdown3_1 are similar 

    3)use one label to display the result, set the label's Text:

    If(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Days)=0,
     If(Dropdown2_1.Selected.Value<17,
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" 
     "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker2.SelectedDate&" 
     "&Dropdown2_1.Selected.Value&":"&Dropdown3_1.Selected.Value,ShortDateTime)),
     Hours
     ),
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" 
     "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker1.SelectedDate&" "&"17"&":00",ShortDateTime)),
     Hours
     )
     ),//if start day and end day is the same day
    If(
     Dropdown2.Selected.Value=17,
     0,
     Dropdown2.Selected.Value<17,
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker1.SelectedDate&" "&"17"&":00",ShortDateTime)),
     Hours) //start day working time
     )+
    (DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Days)-1)*9+
    //interval days' working time
    If(
     Dropdown2_1.Selected.Value=17,
     9,
     Dropdown2_1.Selected.Value<17,
     DateDiff(
     DateTimeValue(Text(DatePicker2.SelectedDate&" "&"8"&":00",ShortDateTime)),
     DateTimeValue(Text(DatePicker2.SelectedDate&" 
     "&Dropdown2_1.Selected.Value&":"&Dropdown3_1.Selected.Value,ShortDateTime)),
     Hours
     ) 
     )//end day working time

     

     If you want to exclude holidays and weekends, firstly you need to follow the link that @KrishnaV  provided to calculate the business day.

    Then use this business day to calculate working time.

    If(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Days)=0,
     If(Dropdown2_1.Selected.Value<17,
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" 
     "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker2.SelectedDate&" 
     "&Dropdown2_1.Selected.Value&":"&Dropdown3_1.Selected.Value,ShortDateTime)),
     Hours
     ),
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" 
     "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker1.SelectedDate&" "&"17"&":00",ShortDateTime)),
     Hours
     )
     ),//if start day and end day is the same day
    If(
     Dropdown2.Selected.Value=17,
     0,
     Dropdown2.Selected.Value<17,
     DateDiff(DateTimeValue(Text(DatePicker1.SelectedDate&" "&Dropdown2.Selected.Value&":"&Dropdown3.Selected.Value,ShortDateTime)),
     DateTimeValue(Text(DatePicker1.SelectedDate&" "&"17"&":00",ShortDateTime)),
     Hours) //start day working time
     )+
    (business day-1)*9+
    //interval days' working time
    If(
     Dropdown2_1.Selected.Value=17,
     9,
     Dropdown2_1.Selected.Value<17,
     DateDiff(
     DateTimeValue(Text(DatePicker2.SelectedDate&" "&"8"&":00",ShortDateTime)),
     DateTimeValue(Text(DatePicker2.SelectedDate&" 
     "&Dropdown2_1.Selected.Value&":"&Dropdown3_1.Selected.Value,ShortDateTime)),
     Hours
     ) 
     )//end day working time

    You need to use business day to calculate interval days' working time.

     

     

     

    Best regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard