How do I convert seconds to minutes, hours, or days with Arcade

1947
3
Jump to solution
01-21-2020 12:25 PM
JacobCaldwell
New Contributor

 Currently our data displays in seconds, but I'd like to set it to display in minutes, hours, or days so that it's easier to read in the pop-up. How can I accomplish this with Arcade?

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi jakecaldwell_ETISoftware ,

Have a look at the example below:

var seconds = 90061;

var result = "";
var days = Floor(seconds / (60 * 60 * 24));
if (days > 0) {result = Round(days,0) + " day(s) "};
seconds -= days * 60 * 60 * 24;
var hours = Floor(seconds / (60 * 60));
seconds -= hours * 60 * 60;
var minutes = Floor(seconds / 60);
seconds -= minutes * 60;
result += Text(hours, "00") + ":" + Text(minutes, "00") + ":" + Text(seconds, "00");

return result

This returns: 

1 day(s) 01:01:01

Just assign the seconds field to the seconds variable on line 1.

View solution in original post

3 Replies
XanderBakker
Esri Esteemed Contributor

Hi jakecaldwell_ETISoftware ,

Have a look at the example below:

var seconds = 90061;

var result = "";
var days = Floor(seconds / (60 * 60 * 24));
if (days > 0) {result = Round(days,0) + " day(s) "};
seconds -= days * 60 * 60 * 24;
var hours = Floor(seconds / (60 * 60));
seconds -= hours * 60 * 60;
var minutes = Floor(seconds / 60);
seconds -= minutes * 60;
result += Text(hours, "00") + ":" + Text(minutes, "00") + ":" + Text(seconds, "00");

return result

This returns: 

1 day(s) 01:01:01

Just assign the seconds field to the seconds variable on line 1.

JacobCaldwell
New Contributor

 This worked great! Thanks!

XanderBakker
Esri Esteemed Contributor

Hi jakecaldwell_ETISoftware , I'm glad it does. You can tweak the way you want to present the results. If you have any additional questions, just post them here and I will get back to you.

0 Kudos