cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
drallam2
Helper I
Helper I

Time Display Format

Hi,

 

I'm having trouble with converting seconds to hh:mm:ss format in a text display.

I'm calculating the seconds based on the difference between two time stamps.

anyhelp will be great!

13 REPLIES 13
MarkNuvair
Frequent Visitor

Just wanted to point something out. I came across this post while I was trying to solve the same problem. Although the marked solution is close, there's a problem with the minutes calculation. When the timer goes over an hour the If statement returns only 0. The corrected solution which will include the minutes calculation past the 1 hour mark should be:

 

Text(RoundDown(UpdateTimer/3600,0),"[$-en-US]00")&":"&
Text(If(RoundDown(UpdateTimer/60,0)>59,
RoundDown((UpdateTimer-(RoundDown(UpdateTimer/3600,0)*3600))/60,0),
RoundDown(UpdateTimer/60,0)),"[$-en-US]00")&
":"&
Text(Mod(UpdateTimer,60),"[$-en-US]00")

 

FYI on this formula, I have the DateDiff function running in a timer somewhere else in my program. Anywhere you see "UpdateTimer" in the equation above you can replace it with: DateDiff(TimeValue(TimerClockIn),TimeValue(Text(Now(),"[$-en-US]hh:mm:ss")),Seconds). However I think PowerApps runs it better when you split that function out, store its' result in a variable, then manipulate it from there. Of course there are syntax's that you could use to eliminate the If statement as well, but I like telling it to use the less intensive formula when it can in order to conserve resources. Maybe I'm not really accomplishing that here(I'm not used to scripting languages), but it feels like it so I'm happy.

 

Hope that helps save someone hours of banging their head against the wall! 🙂

 

PowerDapp2
Advocate I
Advocate I

If you have got time as integer in seconds, e.g. 54977 seconds and you want to have time in 24h format:
15:16:17
you can use:


Text(
RoundDown(
ThisItem.Time / 3600;
0
)
) & ":" &
//mm
Text(
RoundDown(
(ThisItem.Time / 3600 - (RoundDown(
ThisItem.Time / 3600;
0
))) * 60;
0
)
) & ":" &
//ss
Text(
(((ThisItem.Time / 3600 - (RoundDown(
ThisItem.Time / 3600;
0
))) * 60)- RoundDown(
(ThisItem.Time / 3600 - (RoundDown(
ThisItem.Time / 3600;
0
))) * 60;
0
))*60
)

Thanks @bdodu for your suggestion... but looking at the formula I found an error which made minutes become 0 if the time was >1h... and found an easier way to do it.

Text(RoundDown(DateDiff(CurrentTime,InitialTime,Seconds)/3600,0),"00")&":"&
Text(RoundDown(Mod(DateDiff(CurrentTime,InitialTime,Seconds),3600)/60,0),"00")&":"&
Text(Mod(DateDiff(CurrentTime,InitialTime,Seconds),60),"00")

What if I wanted to display the date with this?
DD:HH:MM:SS


Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,147)