I am using datetime
in Arcpy
to convert a "Sample Date"
field in a feature class to the day of the year. The date in the field is in a month/day/year
format and it doesn't include any leading zeros (ex. 7/8/2018
instead of 07/08/2018
).
Whenever I try running the following line of code,
dtm = datetime.datetime.strptime(row, '%Y/%m/%d %H:%M')
I get the following error:
ValueError: time data '[datetime.datetime(2003, 6, 3, 0, 0)]' does not match format '%Y/%m/%d %H:%M'
The sample date field that I am using does not include any time data which I believe is where the two zeros at the end of the error message are coming from. I just assumed that they were hours and minutes but I am not sure.
Does anyone know what the zeros are so that I can change my code to fit the correct format or how I can avoid the zeros altogether? I tried datetime.date
instead of datetime.datetime
as well and still had complications. I can post the long version of the code if needed but the code that I provided is the cause of the error message. I have included the link of the datetime
reference I used. The website is for strftime
not strptime
but I believe that it works the same. Trying strftime
throws an error as well. Link: http://strftime.org/