Select to view content in your preferred language

Date-Range Domains - what gives

2160
3
05-29-2018 04:52 PM
JohnMDye
Frequent Contributor

Could use some help understanding Range Domains configured to use the 'Date' field type.

Step 1. In ArcGIS Pro, I created a new Range Domain in a file gdb configured to use the Date field type.

fgdb = r"C:\Users\johnmdye\Documents\ArcGIS\Projects\MyProject.gdb"
arcpy.CreateDomain_management(
    fgdb, 
    'DateDomain', 
    'My Date-Range Domain', 
    'DATE', 
    'RANGE')‍‍‍‍‍‍‍‍‍

Step 2. Next, I set the Range Domain values. I checked the documentation to see how I needed to format the date inputs but there was no information about formatting dates or passing in a date-time object. All of the examples showed text inputs only.

arcpy.SetValueForRangeDomain_management(
    fgdb,
    'DateDomain',
    '01/01/1980 12:00 AM',
    '05/29/2018 12:00 AM')‍‍‍‍‍‍‍‍‍‍

When I checked the domain after running this, the time had automagically been set to 12:00am for both the minimum and maximum value. This made me assume that ArcGIS Pro had successfully converted my input strings for the min and max parameters to date-time objects.

Step 3. Next, I assigned the domain to a field

table = r"C:\\Users\johnmdye\Documents\ArcGIS\Projects\MyProject.gdb\TEST"
arcpy.AssignDomainToField_management(
    table, 
    'DateField',
    'DateDomain') ‍‍‍‍‍

After that successfully completed, I tried to edit the 'DateField' with the 'DateDomain' assigned to ensure that I could only specify a date between the min and max range, but I was able to enter any date I wanted and save the table. 

I then tried performing the workflow completely through the Pro UI and discovered that after I'd created the 'DateDomain' domain manually, I couldn't assign it to my 'DateField' through the Pro UI. (The circles are my mouse clicks)

So, in this case I jumped back to Step 2 above and executed the SetValueForRangeDomain_management tool to set 'DateDomain' on 'DateField' and it worked, or at least didn't return an error and when I looked at the Field Design for the TEST table, 'DateDomain' was indeed showing as being assigned to 'DateField'.

So, then I added 'TEST' table to a new map and attempted to edit the 'DateField' for a record. Lo and behold, I could enter any date I wanted and save the table. 

I shouldn't be able to set the date to 5/30/2018 because the maximum value on the DateDomain which is assigned to the DateField is '5/29/2018 12:00 AM'

What gives?! Am I doing something wrong? Can anyone else replicate this odd behavior?

3 Replies
RandyBurton
MVP Alum

I have noticed a similar issue with 10.5 desktop.  I performed a test using a range domain on fields of type Long Integer and Date.  Editing a file geodatabase inside ArcMap, I could set the fields to a value outside the range.

0 Kudos
blackcloud77
New Contributor

My experience is that the use of domains will not prohibit the entry of data that does not conform to the configured domains.  You can calculate the fields to whatever you want; or enter the nonconforming data manually.  I think domains are more for convenience and promoting consistency when users are editing data with less sophisticated tools, such as web maps and mobile apps.  They certainly do not enforce data consistency. 

0 Kudos
Katie_Clark
MVP Alum

Writing a follow up here in case the information might help someone else who stumbles on this post like I did. 

For doing this in code, here is an example of code that worked for me:

arcpy.management.SetValueForRangeDomain(
    in_workspace=r"PATH TO YOUR DATABASE",
    domain_name="DateRange",
    min_value="1/1/1900 12:00:00 AM",
    max_value="1/1/2100 12:00:00 AM"
)

 

And if you want to do it in the GUI, if the Field Type is "Date" and the Domain Type is "Range Domain", then when you click within the Minimum or Maximum cells, there will be a GUI calendar input where you can select the date.

Katie_Clark_0-1743791279169.png

 

Best,
Katie

If this answer helped you, please consider giving a kudos and/or marking as the accepted solution. Thanks!
0 Kudos