Select to view content in your preferred language

combining different date and time fields

2570
6
10-12-2011 08:18 AM
AmyMeehan
Deactivated User
I have a rather unique problem.  Not sure if Python is the right way to solve it, but here goes:

I have some satellite (radiotelemetry) location data that I am trying to analyze for movement patterns, etc.  I want to animate certain time periods.  However because of the way the data are downloaded, I have a date field for the date but for the time, I had to make a text field and convert the time into the following format:

hh:mm am/pm

I think I need a singe field to make the animation work the way I want (showing consecutive locations on a map).  I'm not overly familiar with the datetime functions in Python.  Is there a way to combine these two fields into a single datetime field?  Would it be somehow easier to do this with the field calculator? 

Thanks for any suggestions. 

Amy Meehan
Wildlife Biologist
Maine Dept. Inland Fisheries and Wildlife
Tags (2)
0 Kudos
6 Replies
ChrisSnyder
Honored Contributor
Don't know much about "formal" methods of converting date/time formats in Python, but I think there are some built in converters: http://docs.python.org/library/time.html.

I for one absolutely HATE all the different date/time formats that all the different databases use (Oracle vs. FGDB vs. DBF vs SQL vs...)! So one thing I always use (because it's simple) is to convert my disparate date/time fields to a simple long integer (or text) format of YYYYMMDDHHMMSS. So 20111012141239 would be 2:12:39PM on Oct 12, 2011. When reading from left to right, it is then very easy to then parse date/times.... Once everything is in a consistent format, then life is easy.
0 Kudos
KimOllivier
Honored Contributor
Create a date field in your geodatabase (not shapefile) and populate it using the datetime object in Python. The datetime module handles all the messy calculations very well and the animation tools need a date field.

If you have the source data as  separate strings there are easy conversions to a datetime object using datetime.combine(date,time)

The datetime object also knows about time intervals, so you can subtract two dates to get the differences easily, or add useful offsets such as a week, month or year without worrying about days in the month or leap years.

eg
import datetime
print datetime.datetime.now()
0 Kudos
ChrisSnyder
Honored Contributor
Funny that:

>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2011, 10, 12, 21, 8, 37, 327000)


Easy breeze...

Thank you for the reminder about datetime Kim!
0 Kudos
AmyMeehan
Deactivated User
Thank you both!  I will try your suggestions!

Amy
0 Kudos
AmyMeehan
Deactivated User
I managed to get my data into the format Chris suggested and then the Convert to Time field tool actually worked.  Thank you!!

Amy
0 Kudos
deleted-user-IR249IovB3CN
Deactivated User
This is an old thread but I'm going to take a shot. I need to create a date field from 3 separate numeric fields in my feature class - "yr", "mon", and "day", using python. I can not seem to figure this out. Any help is greatly appreciated! Thanks.
0 Kudos