1

I have a field named ORIGDTTIME that contains 12 hour date values such as 06:36 AM. The field is a date data type in my feature class, however when I print the values from this field I am not receiving any of the actual values that are in the feature class. The date field is in a feature class in an Oracle SDE connection. The isue is reproduced in a file geodatabase

Here are the values that are being printed

[datetime.datetime(1899, 12, 30, 13, 50), datetime.datetime(1899, 12, 30, 13, 20), datetime.datetime(1899, 12, 30, 13, 9), datetime.datetime(1899, 12, 30, 13, 45), datetime.datetime(1899, 12, 30, 14, 54), datetime.datetime(1899, 12, 30, 10, 28, 19), datetime.datetime(1899, 12, 30, 12, 48), datetime.datetime(1899, 12, 30, 14, 48), None, datetime.datetime(1899, 12, 30, 10, 36), datetime.datetime(1899, 12, 30, 10, 27), datetime.datetime(1899, 12, 30, 13, 46)].

I am using this script to print the values.

import arcpy
fldName = 'ORIGDTTIME'
fc = 'featureclass'
myList = set([row.getValue(fldName) for row in arcpy.SearchCursor(fc)])
print myList

What should be changed to print the correct values in this script?

  • Where is your date field stored? i.e. where is your feature class stored? If not in a file geodatabase, then when you copy this or a few features into a file geodatabase do you still see the same issue? Whenever you can bring a geodatabase problem into a file geodatabase you widen the number of potential answerers greatly. – PolyGeo Nov 14 '16 at 23:58
  • The date field is in a feature class in an Oracle SDE connection. The isue is reproduced in a file geodatabase. – Geoffrey West Nov 15 '16 at 0:07
  • Please use the edit button beneath your question to revise it with any requested clarifications. – PolyGeo Nov 15 '16 at 0:10
3

You could try this. Its post manipulation though not sure how to get the right values to begin with.

import arcpy
import datetime
fldName = 'ORIGDTTIME'
fc = 'featureclass'
myList = set([(row.getValue(fldName).time()).strftime("%I:%M %p") for row in arcpy.SearchCursor(fc) if row])
print myList

Using test data

import datetime

list = [datetime.datetime(1899, 12, 30, 13, 50), datetime.datetime(1899, 12, 30, 13, 20), datetime.datetime(1899, 12, 30, 13, 9), datetime.datetime(1899, 12, 30, 13, 45), datetime.datetime(1899, 12, 30, 14, 54), datetime.datetime(1899, 12, 30, 10, 28, 19), datetime.datetime(1899, 12, 30, 12, 48), datetime.datetime(1899, 12, 30, 14, 48), None, datetime.datetime(1899, 12, 30, 10, 36), datetime.datetime(1899, 12, 30, 10, 27), datetime.datetime(1899, 12, 30, 13, 46)]


dates = [(item.time()).strftime("%I:%M %p") for item in list if item]


for item in dates:
    print item

Returns

01:50 PM
01:20 PM
01:09 PM
01:45 PM
02:54 PM
10:28 AM
12:48 PM
02:48 PM
10:36 AM
10:27 AM
01:46 PM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.