3

I'm trying to copy the dates from a field called InspectionDate (date data type) to new field called CompletedDate (date data type) but I don't want the time stamp to be copied over. How can I copy just the date in a mm,dd,yyyy format using field calculator. For example copying 1/1/2016 12:00:00 AM to new field as 1/1/2016.

1
  • 2
    Just a guess but perhaps you can try removing the last 12 characters (including spaces) which may leave you with your date: left("InspectionDate", len("InspectionDate") - 12)
    – Joseph
    Feb 29, 2016 at 15:59

5 Answers 5

6

Storing time alone is not supported, but dates can be stored without time. I just happened to be doing this - I have a date field with date/time stamps and I only want date stamps. I used these field calculator settings - replace DATEFIELD with your field name.

Parser: Python

Show Codeblock: checked

Pre-Logic Script Code:

def FindDate(date):
    if date is None:
        return None
    else:
        return date.split(" ").pop(0)

DATEFIELD =

FindDate(!DATEFIELD!)

ArcGIS field calculator screenshot

5

You can't remove the Hours/Minutes/Seconds while using the Date field type. You will have to convert to an alternative field type.

From ESRI on Working with Date Fields:

Enter dates in MM/DD/YYYY hh:mm:ss format

Regardless of how dates are displayed in the table, you can only enter dates in MM/DD/YYYY hh:mm:ss format, enclosed in single quotation marks. For example, to set a date field to 5:00PM on May 27, 2014, you would type '05/27/2014 05:00:00PM', '05/27/2014 5:00PM', or '05/27/2014 17:00:00' (24-hour clock). Storing time alone is not supported—time must always be a component of a date.

To correct I would suggest creating a string(text) field type as it will allow the format you are seeking of MM/DD/YYYY.

1
  • I did need to make a text field as you suggested and I used the left function mentioned by Joseph. Thanks.
    – user19300
    Feb 29, 2016 at 16:35
0

It is important to note that answers that work for ArcGIS Desktop/ArcMap will not work for ArcGIS Pro, and vice versa, because the Field Calculator (or Calculate Field in ArcGIS Pro) treats ArcGIS Date fields differently between the products. The other answers to this question work for ArcGIS Desktop/ArcMap because Field Calculator handles ArcGIS Date fields as Python unicode, but they don't work for ArcGIS Pro because Calculate Field handles ArcGIS Date fields as Python datetime.datetime.

It is also important to note that ArcGIS Date data types (ArcGIS field data types - ArcGIS Pro | Documentation) are a date and time data type, so you can't "remove" the time from it. However, if you set the time to 00:00:00 then ArcGIS software will typically display only the date portion.

ArcGIS Desktop/ArcMap

Since Field Calculator in ArcGIS Desktop/ArcMap retrieves and returns Python unicode, it allows the ArcGIS Date to be manipulated using string methods like str.split.

# Parser/Expression Type: Python

# Expression
!Date_Field!.split()[0] if !Date_Field! is not None else None

Using a Python Conditional Expression to handle SQL NULL, one can avoid having to use a Code Block and instead can put all the Python code in the Expression.

ArcGIS Pro

Since Calculate Field in ArcGIS Pro retrieves and returns Python datetime.datetime, one must manipulate the ArcGIS Date using datetime methods.

# Parser/Expression Type: Python

# Expression
datetime.datetime(!Date_Field!.year, !Date_Field!.month, !Date_Field!.day) if !Date_Field! is not None else None
-1

Your problem might be simpler than you think. Sometimes you may need to export your data to a different format before exploring much more complicated steps like field calculators:

Displaying dates

A coverage or shapefile stores dates in a date field with this format: yyyy-mm-dd. A geodatabase formats the date as datetime yyyy-mm-dd hh:mm:ss AM or PM. Settings on your Windows system determine how the dates are displayed in ArcMap—M/d/yy, MM/dd/yy, yy/MM/dd, and so on. ArcMap uses the system short date format (numerical) for displaying dates

1
  • It reads like this is suggesting exporting and re-importing a dataset to modify the date field, which is way more cumbersome than doing a relatively simple calculation using Field Calculator.
    – bixb0012
    Sep 29, 2022 at 18:38
-1

All you have to do is use the int() function. Int(date&time) yields date only.

1
  • Since ArcGIS Desktop/ArcMap supports multiple parsers with Field Calculator, and this approach doesn't work with both parsers, it is best to state specifically which parser is needed for this approach to work.
    – bixb0012
    Sep 29, 2022 at 18:40

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.