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

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
DavidWilson
Level: Powered On

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

Meneghino
Level 10

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.

DavidWilson
Level: Powered On

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

Meneghino
Level 10

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 Team
Community Support Team

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.
DavidWilson
Level: Powered On

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
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps 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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

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