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

276
3
Jump to solution
01-21-2020 12:25 PM
Highlighted
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?

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
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

Reply
0 Kudos
3 Replies
Highlighted
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

Reply
0 Kudos
Highlighted
New Contributor

 This worked great! Thanks!

Highlighted
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.

Reply
0 Kudos