1

I am attempting to convert string which is formatted like MM/DD/YYYY to an actual date format in Arcade on ArcGIS Online. This is the code I am using.

var cd = split($feature["DATE_"], " ")
var dates = split(cd[1], "/")
var m = dates[0]
var d = dates[1]
var y = dates[2]
return Text(Date(m, d, y), 'MMMM D, Y')

The output in the example instance that I am using should be August 26, 2019 but it spits out July 9, 1915. The issue is in the last line somewhere, as returning y gives 2019, d gives 26, and m gives 8.

Does anybody know why it may be outputting the incorrect date?

1 Answer 1

1

The way you are using the date function is incorrect. If you follow the date function documentation you will see that the year comes first, not month. Try this:

var cd = split('08 26 2019', " ")
console(cd)
var dates = cd
var m = dates[0] - 1 // Month 0 is January
var d = dates[1]
var y = dates[2]
console(m,d,y)
return Text(Date(y, m, d), 'MMMM D, Y')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.