Select to view content in your preferred language

create a unique ID using date and time using Arcade

210
6
Jump to solution
Friday
dsinha
by
Frequent Contributor

Hello,

I am trying to create a unique id based on date and time at the moment of collection. The value has to be integer and in the format of YY-MM-HHmmss (2026-05-110356). I have seen how to do it using the Text function in arcade, but I can't seem to locate the expression that I need to generate the output in integer form.

Any help would be appreciated.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

To get your format of "2026-05-110356" (did you want to leave out the day?), you would use the syntax

Text(Now(), "Y-MM-HHmmss")

//if you want to include the day, use this syntax
Text(Now(), "Y-MM-DD-HHmmss")

However, this cannot be converted into an integer with the dashes included. You can use this syntax to return an integer

Number(Text(Now(), "YMMHHmmss"))

View solution in original post

6 Replies
KenBuja
MVP Esteemed Contributor

To get your format of "2026-05-110356" (did you want to leave out the day?), you would use the syntax

Text(Now(), "Y-MM-HHmmss")

//if you want to include the day, use this syntax
Text(Now(), "Y-MM-DD-HHmmss")

However, this cannot be converted into an integer with the dashes included. You can use this syntax to return an integer

Number(Text(Now(), "YMMHHmmss"))
dsinha
by
Frequent Contributor

Thanks @KenBuja! I just realized also that the dashes are the problem. Strange that I can store the same value with the dashes in Survey123 as an integer but not in FieldMaps.

0 Kudos
dsinha
by
Frequent Contributor

@KenBuja I just ran into another related issue and I was wondering if you would know how it can be resolved.

The expression Number(Text(Now(), "YMMHHmmss")) works fine in the console and I saved the form to the map and layer in FieldMaps Designer. But when I open the form in FieldMaps on the mobile device, the id number is not calculating and I am getting the error message "Value is invalid".

Any suggestions? Thanks!

 

0 Kudos
KenBuja
MVP Esteemed Contributor

The number you're calculating is probably too big for a regular integer field.

A small integer field (16-bit) only allows for values from -32,768 to 32,767. An integer field (32-bit) allows for values from -2,147,483,648 to 2,147,483,647. Both of these are shorter than what you want.

A big integer field (64-bit) allows for values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

0 Kudos
TravisSaladino
Esri Contributor

Just a thought here... And @KenBuja has touched on this in the past too (see: https://community.esri.com/t5/developers-questions/how-to-convert-datetime-to-epoch-time-in-arcade/m...) ... but would using the Unix epoch time help with any of this? It's not as user friendly as YYYYMMDDmmss but it's already an integer. Just a thought. 

dsinha
by
Frequent Contributor

Thanks @KenBuja and @TravisSaladino for your suggestions. Due to impending deadline on Friday, I decided to convert the field type to text and use Text(Now(), "Y-MM-DD-HHmmss") function.

0 Kudos