Select to view content in your preferred language

Update a field based on date

852
2
06-07-2013 11:46 AM
DamonOsbourne
Emerging Contributor
How can I update a field based on if the date in another field has passed or not?  In other words, which arcpy function or method can be used that will change an attribute from "current" to "expired" when the date in the date field associated with that feature has passed?  The goal is to have a tool/button that updates the features based on date and then exports to pdf.
Tags (2)
0 Kudos
2 Replies
markdenil
Frequent Contributor
There are a few different ways to get the current date and time from the system using Python.
for example...
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2013, 6, 10, 7, 59, 43, 458000)
>>>

This returns a datetime object
Your date field value can be retrived and compared to the now object.
The later date / time value will be greater

If your date fields are strings, you can turn them into datetaime objects using
datetime.strptime(date_string, format)
The python standard library has a list of the format tags.
0 Kudos
RhettZufelt
MVP Notable Contributor
If you are trying to update the field on the currently selected feature(s), then CalculateField_management would do it.

If itering through all the features in your FC, might iterate through with UpdateCursor, if date &LT current date, then update field.

R_
0 Kudos