4

I have a Date column called readings_measurement_tstamp stored in my feature class. I would like to add a String column to this feature class and Field Calculate it to be be just the %H:%M:%S component of readings_measurement_tstamp. After adding the new column I calculated it according to the following expression: datetime.datetime.strftime( !readings_measurement_tstamp! ,'%H:%M:%S')

I was under the impression that Date columns can be referenced like python datetime objects. Therefore, I was very confused when running the field calculator with this expression gave the following error: Descriptor 'strftime' requires a 'datetime.date' object but received an 'str'

The error implies to me that readings_measurement_tstamp is being stored as text, not as a Date. Any ideas what I need to do in order to be able to access readings_measurement_tstamp as a datetime object? Thanks!

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Dec 18, 2013 at 8:03

1 Answer 1

4

Try this code. !UT! is a date field in my FeatureClass storing date and time in the format of "22/11/2012 11:23:30"

import datetime
from dateutil import parser
def convert(ut):
 dateobject = parser.parse(ut)
 return datetime.datetime.strftime(dateobject,'%H:%M:%S')

The Expression you apply to your string field in the Field Calculator would be

convert(!UT!)
answered Dec 18, 2013 at 18:25
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.