Select to view content in your preferred language

Dates Dissapearing?

344
1
Jump to solution
08-07-2012 03:17 PM
ZulyG
by
New Contributor
I am trying to go from a table  (csv file) to a feature class. I have a field called "Dates". When I put the table in and check its field type it says it is of type "Date" (which is what I need) and every record is filled out. However, when I create a feature class:

arcpy.MakeXYEventLayer_management(in_table,x_coord,y_coord,out_table,spatialRef)
'

My output is a feature class.. but with "NULL" dates. I tried to do this by right clicking the table and telling it to display XY data. But The same problem happens. All the dates dissapear..

the dates are in the following form : 08/08/2012

any reason why this could happen?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KimOllivier
Regular Contributor II
Loading dates is always tricky. Do you have a schema.ini file to define the schema of your csv file?
That will help a lot. You will also have to have your date defined in a format that Microsoft can understand.
You specify the DateTimeFormat in the schema.ini file.

If that is not working, then you will need to run a script that reads in the date as a string field, parse it to a python datetime object and then write it out to a date field. I hope you are not using shapefiles, because that can only handle a date without time.

See the GPX to Featureclass conversion tool in 10.1 for an example. Unfortunately the tool to do this conversion does not work in 10.1, so I wrote a Python snippet:

from datetime import datetime from dateutil import tz ## xxxxxxxxxxxxxx snip xxxxxxxxxxxxxxxxx     cur = arcpy.InsertCursor(outFC,srWGS84)      # Loop over each point in the tree and put the information inside a new row     #     for index, trkPoint in enumerate(GeneratePointFromXML(tree)):         if trkPoint.asPoint() is not None: ##            rowsDA.insertRow([trkPoint.name, trkPoint.desc, trkPoint.gpxtype, trkPoint.t, ##                              float(trkPoint.z), float(trkPoint.x), float(trkPoint.y), float(trkPoint.z)])             row = cur.newRow()             row.Name = trkPoint.name             row.Descript = trkPoint.desc             row.Type = trkPoint.gpxtype             row.DateTimeS = trkPoint.t             # convert UTC to nz using Python because ArcGIS tool crashes at 10.0             utc = datetime.strptime(trkPoint.t,'%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=from_zone)             # Tell the datetime object that it's in UTC time zone since              # datetime objects are 'naive' by default             # Convert time zone back for ArcGIS             local = utc.astimezone(to_zone).replace(tzinfo=None)             row.DateTime = local             row.Elevation = float(trkPoint.z)             row.shape = arcpy.Point(float(trkPoint.x), float(trkPoint.y), float(trkPoint.z))             cur.insertRow(row)         else:             badPt +=1

View solution in original post

0 Kudos
1 Reply
KimOllivier
Regular Contributor II
Loading dates is always tricky. Do you have a schema.ini file to define the schema of your csv file?
That will help a lot. You will also have to have your date defined in a format that Microsoft can understand.
You specify the DateTimeFormat in the schema.ini file.

If that is not working, then you will need to run a script that reads in the date as a string field, parse it to a python datetime object and then write it out to a date field. I hope you are not using shapefiles, because that can only handle a date without time.

See the GPX to Featureclass conversion tool in 10.1 for an example. Unfortunately the tool to do this conversion does not work in 10.1, so I wrote a Python snippet:

from datetime import datetime from dateutil import tz ## xxxxxxxxxxxxxx snip xxxxxxxxxxxxxxxxx     cur = arcpy.InsertCursor(outFC,srWGS84)      # Loop over each point in the tree and put the information inside a new row     #     for index, trkPoint in enumerate(GeneratePointFromXML(tree)):         if trkPoint.asPoint() is not None: ##            rowsDA.insertRow([trkPoint.name, trkPoint.desc, trkPoint.gpxtype, trkPoint.t, ##                              float(trkPoint.z), float(trkPoint.x), float(trkPoint.y), float(trkPoint.z)])             row = cur.newRow()             row.Name = trkPoint.name             row.Descript = trkPoint.desc             row.Type = trkPoint.gpxtype             row.DateTimeS = trkPoint.t             # convert UTC to nz using Python because ArcGIS tool crashes at 10.0             utc = datetime.strptime(trkPoint.t,'%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=from_zone)             # Tell the datetime object that it's in UTC time zone since              # datetime objects are 'naive' by default             # Convert time zone back for ArcGIS             local = utc.astimezone(to_zone).replace(tzinfo=None)             row.DateTime = local             row.Elevation = float(trkPoint.z)             row.shape = arcpy.Point(float(trkPoint.x), float(trkPoint.y), float(trkPoint.z))             cur.insertRow(row)         else:             badPt +=1
0 Kudos