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

How to calculate the difference between two times one from a data source and now.

Hi All,

 

I've managed to get my clock working but now I'm trying to calculate the time difference between a saved date:time in a table and now.

 

I have a Table in a Data source titled "EWDData2" with a column titled "Time".

 

i also have the current time updating in my textbox titled "textbox1".

 

I'd like to ideally get the difference to show in the text format hh:mm:ss

 

Here's what I have so far but its not working, hoping you can help.

 

DateDiff(Last(EWDData2).Time,textbox1,Seconds)

 

Thanks in advance for any help you can provide

 

 

Dave

6 REPLIES 6
Highlighted
Helper II
Helper II

Re: How to calculate the difference between two times one from a data source and now.

Hi All,

 

I've managed to get a calculation but it doesn't update with the timer.

 

The calculation that gives a static number is

 

DateDiff(DateValue(Last(EWDData2).Time),DateValue(textbox1),Seconds)

 

I have a timer added to textbox1 but even though textbox1 updates DateDiff doesn't.

 

Also I'd like to have the result shown in hh:mm:ss format but not sure how to do this?

 

Would really appreciate any help

 

Cheers

 

 

Dave

Highlighted
Community Champion
Community Champion

Re: How to calculate the difference between two times one from a data source and now.

I would suggest storing the current datetime in a context or global variable instead (also updated by timer).  Much as PowerApps touts the use of text boxes (labels) to store values for further calculations, the implementation is messy.  A lot of PowerApps is messy, I wish more time was spent by the product team in clearing this up than creating new functionality.

Highlighted
Helper II
Helper II

Re: How to calculate the difference between two times one from a data source and now.

Hi Meneghino,

 

Thanks for all your help so far, you'v been awesome with your assistance. First up your suggetion of using

 

DateDiff(Last(EWDData2).Time, DateTimeValue(textbox1.Text), Seconds)

 

didn't work, it didn't ike the text box when it was expecting a value.

 

I'll try the global variable route when I get a chance.

 

Cheers and thanks again

 

 

Dave

Highlighted
Community Champion
Community Champion

Re: How to calculate the difference between two times one from a data source and now.

Hi @DavidWilson

Not sure why it doesn't work.  Travelling today so a bit difficult, but do reach out tomorrow if you still haven't resolved it.

Highlighted
Community Support
Community Support

Re: How to calculate the difference between two times one from a data source and now.

Hi @DavidWilson,

 

Calculating date difference would require the two time string in the same date/Time format.

So to make it work, it should be:

DateDiff(DateTimeValue(Last(EWDData2).Time), DateTimeValue(textbox1.Text), Seconds)

By the way, based on what I know, there is no proper function that would convert the time interval into the HH:MM: SS format.

 

PowerApps would have the Time field from SQL Server displayed in the format below:

P1Y2M10DT2H30M

See the following thread for more details: SQL Server Time column formatting

 

If you would like to have a function which would format time interval into HH:MM: SS format, then please consider submit it as an idea, in the following site:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Helper II
Helper II

Re: How to calculate the difference between two times one from a data source and now.

Hi Michael,

 

Sadly that doesn't work either, but I did manage to get it to work using the following.

 

DateDiff(DateTimeValue(Last(EWDData2).Time), DateTimeValue(textbox1), Seconds)

 

That formula is to let a driver know how long they have been driving.

 

I now want to work out how to add a label for a time field in the future from when they started driving.

 

i.e. If the time stamp for EWDData2 was at 12:00am I'd like to create a label 5 and a half hours from that time as thats the momst hours they are allowed to drive.

 

I tried this but it didn't work

 

Text(DateTimeValue(Last(EWDData2).Time) + DateTimeValue(330), Minutes)

 

Thanksing everyone for your help with this.

 

Regards

 

 

Dave

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

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