cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Impactful Individual
Impactful Individual

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
Highlighted
Impactful Individual
Impactful Individual

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)))

Highlighted
Frequent Visitor

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

 

Highlighted
Impactful Individual
Impactful Individual

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
Regular Visitor

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.

Highlighted
Super User
Super User

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.

Highlighted
Community Champion
Community Champion

Re: Calculating the difference between two date/times

Thank you all for your help with this issue!

 

@TopShelf-MSFT

Highlighted
Helper I
Helper I

Re: Calculating the difference between two date/times

This worked for me! Thank you!

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (5,701)