Trouble with dates
What do we do when our data doesn’t look right? Well, we check the source, and that’s where things got weirder. When viewing the sale dates in ArcMap, the data showed the correct date. Her parcel record showed a sale date of March 18th. Republishing the data repeated the same scenario. How could the same data show one date in one technology, and another date in another format?
Time Zone Issues
The answer lies in time zones, and how both ArcGIS Server and your browser treat dates and times. If you store your data in an ArcGIS Server geodatabase, attributes with date formats are stored down to the millisecond. However, you can specify in your maps and data whether you’re interested in dates, times, or dates and times. If you’re only interested in dates, the times default to midnight UTC (Universal Time, formerly Greenwich Mean Time). In fact, until ArcGIS Server 10.4, you couldn’t specify any other time zone.
Okay, so dates were stored with a time of midnight UTC on the client’s server. ArcMap knew that, and treated the dates the same way. That’s how the sale date showed correctly on the client’s map for the service. When the map service was republished, and the data was queried through the REST service, the dates returned really big numbers, which represent the number of milliseconds between that date, and January 1, 1970 at midnight UTC.
Why, then, were the results showing different dates as if they were the day before on the website? When the browser works with dates, it knows something that ArcMap doesn’t account for… your time zone. Based on your browser’s location in the world, it can tell what time zone you’re in, and whether it honors daylight savings time.
Resetting your dates
Dates in ArcGIS Online Popups
Why doesn’t ArcGIS Online do something like this?
The short response: How do you really know WHEN to apply this date formatting?
The longer response:
The truth is, it’s really hard to know when to apply this date/time fix. ArcMap is a desktop application that can keep track of a number of file-specific configurations, like removing time from dates, or showing numbers as currency. However, the ArcGIS REST API does not expose those custom formats. Numbers are numbers, whether they should be currency, area, or years. Date stamps are date stamps, whether the time is necessary or not. It’s up to the application consuming the map service data to display fields in the correct format.
We made a number of assumptions with the date hacks we added (each date at midnight UTC should be fixed, for one). Not everybody would like their data tweaked like that. You can’t please all the people all the time. That’s why I don’t mind patching it in as a hack on some of my applications.