Arcade Second() Function Cutting Off Leading Zero

297
6
Jump to solution
09-12-2019 02:32 PM
Highlighted
Occasional Contributor II

So I'm calculating total drive times in Network Analyst. I have an end time field that I'm trying to strip the minutes and seconds from for a new field. It's a date field formatted like so: 9/16/2019 8:01:06 AM. I enter Minute(EndTime) + ":" + Second(EndTime) in the field calculator. The issue is, I'm getting resulting times like 1:6 which should read 1:06, or one minute, six seconds. What gives??

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor II

I used this Text(EndTime, 'mm:ss')

View solution in original post

6 Replies
Highlighted
MVP Regular Contributor

Levi Cecil‌,

Try the following: Text(EndTime, 'm:ss')

Highlighted
Esri Esteemed Contributor

Hi Levi Cecil ,

In addition to the correct answer provided by Lance Cole , it is important to understand that the Second function returns a number, not a text: 

Second( dateValue ) -> returns: Number

See: Date Functions | ArcGIS for Developers 

You want to get the result in a certain format and that is obtained by using the Text function as Lance described. In this case you don't have to use the Second and Minute functions, but by providing the desired format "m:ss" or "mm:ss" (what ever suits your need most) you can use a single function. To see more formatting options, please see: Data Functions | ArcGIS for Developers 

Highlighted
Occasional Contributor II

Thanks Xander. This works, but only for times over one minute (see screenshot).

Reply
0 Kudos
Highlighted
Occasional Contributor II

I used this Text(EndTime, 'mm:ss')

View solution in original post

Highlighted
Esri Esteemed Contributor

Hi Levi Cecil ,

I tested this in the playground here: ArcGIS Arcade | ArcGIS for Developers  and it works there if I define a date as the one you have:

When I do the same in ArcGIS Pro:

It also seems to work:

Not sure what is going wrong in your case...

Reply
0 Kudos
Highlighted
Occasional Contributor II

I added the extra 'm' to your original solution Text(EndTime, 'mm:ss'). A single 'm', Text(EndTime, 'm:ss') results in an empty string if the time is less than a minute.