Date - Today's date in Python?

13372
20
Jump to solution
06-13-2013 09:48 AM
ionarawilson1
Occasional Contributor III
Hi guys,

I am writing a python script that adds a feature to geodatabase feature class. Some fields the user has to enter manually and some are automatic. However the date field output is an incorrect date of 7/5/1905. Does anybody have any idea why this is happening? I have tried everything I could find and nothing worked. I am using a file geodatabase, the date field is of date type and my computer's setting has the correct today's date. Thank you for any help!

Here is the code

#Calculate Date Field expression = time.strftime("%Y") arcpy.CalculateField_management("Boundary", "Date", expression, "PYTHON")


If I change the code I get a date of 3/29/1969. Here is the code for that:

#Calculate Date Field                                                     import time                                                               import datetime                                                           now = datetime.date.today()                                               expression = now.strftime("%m%d%y")                                                                                                                 arcpy.CalculateField_management("Boundary", "Date", expression, "PYTHON")
Tags (2)
20 Replies
ionarawilson1
Occasional Contributor III
Hi Niklas,

Sorry for the delay in replying. I was on vacation. Can you please elaborate on CalculatingField being a problem? What would be the correct way to calculate the date if I used another method? Thank you!
0 Kudos