Hi, I have a date field called date with date times in format 4/1/2016 6:40:00 AM
I have a second field called times that is a double with numbers of seconds.
I would like to use arcpy.CalculateField_management to add the seconds to the time in a new date field called futuretime.
I can do this in the field calculator in VB using:
DateAdd ( "s", [times], [date] )
But I am trying to use a script to run through a bunch of files in a for loop.
I started with
for files in allFC:
arcpy.CalculateField_management(files, "futuretime",?????, "PYTHON_9.3",????)
but I can not figure out the code to fill into the ?????s
Thanks for any help,
Ian
Solved! Go to Solution.
You can use timedelta to add the two attributes together. For example,
arcpy.CalculateField_management(files, "futuretime", "datetime.datetime.strptime(!date!,'%d/%m/%Y %H:%M:%S') + datetime.timedelta(seconds=!seconds!)", "PYTHON_9.3")
You may want to check the datetime module to make sure I've got the format right.
You can use timedelta to add the two attributes together. For example,
arcpy.CalculateField_management(files, "futuretime", "datetime.datetime.strptime(!date!,'%d/%m/%Y %H:%M:%S') + datetime.timedelta(seconds=!seconds!)", "PYTHON_9.3")
You may want to check the datetime module to make sure I've got the format right.
Jon, Thanks so much. It worked perfectly. Really appreciate the help.
Ian