Extend Format Date activity with ArcGIS formats
PlannedSay I queried a feature that has a date attribute, and then I want to use that date value in another query. According to the Esri documentation, The format of a date in a query should be either DATE 'YYYY-MM-DD' or TIMESTAMP 'YYYY-MM-DD HH:MI:SS'.
It would help if the Format Date activity was capable of outputting those formats (excluding the words DATE or TIMESTAMP and single quotes). Note that the time part should be local, not GMT, so $formatDate.iso is not helpful in this case.
My current workaround is to create a Date object first: new Date($feature.attributes["mydate"]), and then format a timestamp: =`TIMESTAMP '${$myDate.result.getFullYear()}-${$myDate.result.getMonth() + 1}-${$myDate.result.getDate()} ${$myDate.result.getHours()}:${$myDate.result.getMinutes()}:${$myDate.result.getSeconds()}.${$myDate.result.getMilliseconds()}'`
Needless to say that this is a whole lot of work for something that should be easy
-
You might be able to find a locale that give you what you want. I know that the date part you're describing is the same as we use in Canada, so this would work:
=(new Date()).toLocaleDateString("en-CA")
You'd need to just double check it doesn't convert the time zone or anything, but I think the locale is purely about formatting here.
0 -
Thanks Ken,
I hadn't expected any locale to use y-m-d format, but there you go :-)
If I need both the date and the time, it is also shorter than my initial approach, but still a bit cumbersome, e.g.
=(new Date()).toLocaleDateString("en-CA") + “ ” + (new Date()).toLocaleTimeString("nl-NL"),
or (as UTC)
=(new Date()).toISOString().replace(/[TZ]/g, ' ')
I think the extra output to Format Date can still be useful. This could also deal with a timezone conversion. As you probably know, ArcGIS uses UTC by default, so an extra boolean input Convert to UTC could help here.
0 -
Yes, I quite like the official Canadian date format. Things like receipts can often be a mix of d/M/y and M/d/y which is pretty confusing but any time I see a four-digit number at the start, I know what I'm dealing with!
Maybe instead of a new output, a different value for the format input would be appropriate.
Something like format: “esri” maybe?
I don't think I want to introduce UTC conversion here as I don't want to stray from formatting into conversion. I'd rather focus on the new Calculate Date activity for that sort of thing.
1 -
Sounds all good to me
0 -
This has been added to the backlog. (User Story #312336)
I think we could support something similar to Microsoft's Custom date and time format strings.
0
Please sign in to leave a comment.
Comments
5 comments