cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
anilc59
Level: Powered On

Calculating the difference between two date/times

Hi All,

I am new to the Power Apps. I am unable to get the time difference, trying to get total time from activity endTime - Activity Start Time. I want the output in Hours, minutes and second format.

 

I have a data for start time and end time on Lable and also want to display the difference of time on lable only.

 

Please let me know best possilbe solution.

 

Thanks
Anil

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Calculating the difference between two date/times

If you're using a label and not a date picker then you have to first convert the label text to a datetime before you can get the difference.  Here's how you would do that:

 

DateDiff(DateTimeValue(Label6.Text),DateTimeValue(Label5.Text),Days)

View solution in original post

7 REPLIES 7
Super User
Super User

Re: Calculating the difference between two date/times

This might not be the best way so someone else chime in if it isn't but here's how I've accomplished this in the past.  There's a function called DateDiff which will get the difference between two dates.  One of the parameters for this function lets you define what unit you want to return the difference in (hours, minutes, seconds, etc).  You can't do all at once so you'll have to combine the values to get it in Hours, Minutes, Seconds format.  Here's an example:

 

Concatenate(Text(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Hours)),":",Text(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Minutes)),":",Text(DateDiff(DatePicker1.SelectedDate,DatePicker2.SelectedDate,Seconds)))

anilc59
Level: Powered On

Re: Calculating the difference between two date/times

Thanks for your input!

 

But I am not using date picker. I will tell you the scenario.

 

I have a command button and on select event of command button it will capture current date and time on lable(lable1). Once the user finished his activity it will capture end time on another lable(lable2). Always I am getting errror "Invalid argument Type (Text). Expecting  date and time instead.

 

Thanks you in advance

 

Super User
Super User

Re: Calculating the difference between two date/times

If you're using a label and not a date picker then you have to first convert the label text to a datetime before you can get the difference.  Here's how you would do that:

 

DateDiff(DateTimeValue(Label6.Text),DateTimeValue(Label5.Text),Days)

View solution in original post

Highlighted
GHornberger
Level: Powered On

Re: Calculating the difference between two date/times

Keep in mind though, when you are dealing with time intervals like minutes there is also an am and pm element you need to consider.

seadude
Level 10

Re: Calculating the difference between two date/times

Hi @anilc59. There are many great posts in the forum on this exact topic.
For Example: @CarlosFigueira's great solution here. Please consider using "Search all content" in the top right corner of the forum.

TopShelf-MSFT
Level 10

Re: Calculating the difference between two date/times

Thank you all for your help with this issue!

 

@TopShelf-MSFT

racheljgood119
Level: Powered On

Re: Calculating the difference between two date/times

This worked for me! Thank you!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,907)