Arcade expression to format date

4455
4
06-25-2023 06:33 PM
FrankHerbert
Occasional Contributor

I have created an Arcade expression to group attributes and return them in a list. I'm very new to Arcade and having trouble understanding how to format the date. I have attached an image of the expression showing my progress.

Currently the date is returned as "Jun 23, 2023, 10:31:00 AM GMT+12" but I would like to see it as 23/06/23.

Please can someone tell what I need to fix to change this?

Thanks in advance.

0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

this may be useful

Date functions | ArcGIS Arcade | ArcGIS Developers


... sort of retired...
0 Kudos
SSchott_CLAU
Occasional Contributor

@FrankHerbert , you can use the date functions as mentioned above.

Below is the code which I use in my maps to format the dates.

Day($feature.date) + "/" + ISOMonth($feature.date) + "/" + ISOYear($feature.date)

SSchott_CLAU_0-1687754512199.png

 

KenBuja
MVP Esteemed Contributor

The Text function is very handy to make various date strings

Text(Now(), 'YY/MM/DD');

 

0 Kudos
MHergel
Occasional Contributor

Hi,

To get the date to be returned in a YYYY/MM/DD format you could try

var dateWithoutTime = Left(group.Date, 10);

group.Date is where you would put the field or variable that the date information is stored in. Below is an example of how I used this in my arcade code in AGOL Map Viewer to print out dates from a group in a chronological list.

 

for (var group in ordered){
// Extract date part from group.Date
var dateWithoutTime = Left(group.Date, 10); // Assuming group.Date is in 'YYYY-MM-DD' format
list += dateWithoutTime + TextFormatting.NewLine;
}

list

 

I hope this helps 😊

0 Kudos