<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Datetime from CSV file in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162286#M5463</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you supply a sample of your data?&amp;nbsp; Your code is hard to read without indentation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Nov 2012 13:46:50 GMT</pubDate>
    <dc:creator>BruceHarold</dc:creator>
    <dc:date>2012-11-07T13:46:50Z</dc:date>
    <item>
      <title>Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162285#M5462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good day. I am trying to parse a large amount of data (in CSV format) into minute intervals and then geocode the data into a geodatabase. Problem is that the datetime field does not display as text format in the geodatabase. It still shows a DATE format. The CSV file has the proper YYYY-MM-DD HH:MM text format after parsing. I have converted the date field to text format prior to geoprocessing but the data still appears to be processed in ArcGIS in date format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know shapefiles do not support the HH:MM timestamp date format so I have performed a text conversion on the date:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; dt = DTTM[:19]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; str_date = dtime.strftime('%Y-%m-%d %H:%M')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the datetime field is set as text format in the schema.ini file prior to geoprocessing. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[1output.csv]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Format=CSVDelimited&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Col4=DTTM Text&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have also tried to write directly from the CSV to a file geodatabase, using CopyRows, i.e. arcpy.CopyRows_management(filename, geodb), but the geodatabase still contains the date format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas what is going on?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for all responses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My code snippets are included below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;min_interval.py:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import csv&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from datetime import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def min_aggr(infile, outfile):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; ifile = open(infile, 'rb')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; reader = csv.reader(ifile)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; out = open(outfile, 'wb')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; writer = csv.writer(out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; header = reader.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; hdr = ['ID','LON','LAT','DTTM','HEADING','CALL_SIGN','vesselType']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; writer.writerow(hdr)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; for ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType in reader:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; dt = DTTM[:19]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; str_date = dtime.strftime('%Y-%m-%d %H:%M')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; data = [ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; writer.writerow(data)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;filenum = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = raw_input("Enter the full path name (ex. c:\\test\):")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datapath = raw_input('Enter the path for the output directory (ex. c:\\output\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList=os.listdir(path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList.sort()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fname in dirList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; filenum += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; filename = path + fname&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; outfile = datapath + str(filenum) + 'output.csv'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; min_aggr(filename, outfile)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; except IOError:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print filename&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'files have been processed'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;geocode.py:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;coord = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" #spatial projection&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#create file geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dir = raw_input('Enter path to create geodatabase (ex. c:\\data\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dbname = raw_input('Enter the name for the geodatabase (ex. test.gdb):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CreateFileGDB_management(dir, dbname)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'geodatabase ' + dbname + ' has been created'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;geodb = dir + dbname&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;filenum = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = raw_input('Enter the full path name for input files (ex. c:\\test1\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datapath = raw_input('Enter the path for the output directory (ex. c:\\output1\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList=os.listdir(path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList.sort()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fname in dirList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; filenum += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; filename = path + fname&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; shp = datapath + str(filenum) + 'output.shp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.MakeTableView_management(filename,'View')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.MakeXYEventLayer_management('View','LON','LAT','Layer')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CopyFeatures_management('Layer', shp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.DefineProjection_management(shp, coord)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.FeatureClassToGeodatabase_conversion([shp], geodb)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print 'file ' + filename + ' has been geoprocessed'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; except IOError:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print 'ERROR: ' + filename&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'geoprocessing complete'&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Nov 2012 14:46:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162285#M5462</guid>
      <dc:creator>JimKrist</dc:creator>
      <dc:date>2012-11-06T14:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162286#M5463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can you supply a sample of your data?&amp;nbsp; Your code is hard to read without indentation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 13:46:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162286#M5463</guid>
      <dc:creator>BruceHarold</dc:creator>
      <dc:date>2012-11-07T13:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162287#M5464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry about the code indent. Didn't realize I needed to use the INDENT tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sample .csv data (including header):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0,-74.064842,40.617940,2010-01-01 00:01,0,WS0286,Other&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0,-90.910605,30.080466,2010-01-01 00:02,0,WS0286,Other&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;0,-74.064867,40.617936,2010-01-01 00:03,0,WS0286,Other&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1,-90.216484,29.125813,2010-01-01 00:00,511,FF0419,Cargo&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1,-89.315449,29.047325,2010-01-01 00:00,511,FF0419,Cargo&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1,-90.216495,29.125843,2010-01-01 00:01,511,FF0419,Cargo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scripts with indentation:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;min_interval.py:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import csv&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from datetime import datetime&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def min_aggr(infile, outfile):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT] ifile = open(infile, 'rb')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;reader = csv.reader(ifile)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;out = open(outfile, 'wb')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;writer = csv.writer(out)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;header = reader.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;hdr = ['ID','LON','LAT','DTTM','HEADING','CALL_SIGN','vesselType']&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;writer.writerow(hdr)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType in reader:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]dt = DTTM[:19]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;str_date = dtime.strftime('%Y-%m-%d %H:%M')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data = [ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;writer.writerow(data)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;filenum = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = raw_input("Enter the full path name (ex. c:\\test\):") datapath = raw_input('Enter the path for the output directory (ex. c:\\output\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList=os.listdir(path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList.sort()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fname in dirList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]filenum += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename = path + fname&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outfile = datapath + str(filenum) + 'output.csv'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]min_aggr(filename, outfile)[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except IOError:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]print filename[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'files have been processed'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;geocode.py:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;env.overwriteOutput = True&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;coord = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" #spatial projection&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#create file geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dir = raw_input('Enter path to create geodatabase (ex. c:\\data\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dbname = raw_input('Enter the name for the geodatabase (ex. test.gdb):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CreateFileGDB_management(dir, dbname)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'geodatabase ' + dbname + ' has been created'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;geodb = dir + dbname&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;filenum = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;path = raw_input('Enter the full path name for input files (ex. c:\\test1\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datapath = raw_input('Enter the path for the output directory (ex. c:\\output1\):')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList=os.listdir(path)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dirList.sort()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for fname in dirList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]filenum += 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename = path + fname&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;shp = datapath + str(filenum) + 'output.shp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]arcpy.MakeTableView_management(filename,'View')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeXYEventLayer_management('View','LON','LAT','Layer')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management('Layer', shp) arcpy.DefineProjection_management(shp, coord)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToGeodatabase_conversion([shp], geodb) print 'file ' + filename + ' has been geoprocessed'[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;except IOError:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]print 'ERROR: ' + filename[/INDENT][/INDENT][/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'geoprocessing complete'&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 14:41:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162287#M5464</guid>
      <dc:creator>JimKrist</dc:creator>
      <dc:date>2012-11-07T14:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162288#M5465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Sorry about the code indent. Didn't realize I needed to use the INDENT tool.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Jim, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't know what's going on with your data, but I just wanted to let you know there's a more effective way to post code on the forum... As it stands now, if someone copies and pastes your code into a Python script, they loose all the indentation, so it's pretty much a mess.&amp;nbsp; Instead, use the CODE tags...There's a little button that looks like a number sign (#).&amp;nbsp; You can click that and CODE tags appear.&amp;nbsp; Paste your code between these tags and it will retain the same indentation as you had in the script.&amp;nbsp; Here's an example of what it looks like when you use the code tags:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in fs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type = desc.DataType
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if type in fDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fDict[type].append(f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #...and so forth
 &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:31:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162288#M5465</guid>
      <dc:creator>LT</dc:creator>
      <dc:date>2021-12-11T08:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162289#M5466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Aren't you writing out the exact same input to the output? You put the datetime into a string (str_date) but never write it to the output.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType in reader:
&amp;nbsp; dt = DTTM[:19]
&amp;nbsp; dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
&amp;nbsp; str_date = dtime.strftime('%Y-%m-%d %H:%M')
&amp;nbsp; data = [ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType]
&amp;nbsp; writer.writerow(data)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm guessing it should be something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;data = [ID,LON,LAT,str_date,HEADING,CALL_SIGN,vesselType&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:07:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162289#M5466</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T16:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162290#M5467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Aren't you writing out the exact same input to the output? You put the datetime into a string (str_date) but never write it to the output.&amp;nbsp; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;for &lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType&lt;/SPAN&gt; in reader:
&amp;nbsp; dt = DTTM[:19]
&amp;nbsp; dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
&amp;nbsp; str_date = dtime.strftime('%Y-%m-%d %H:%M')
&amp;nbsp; data = [&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;ID,LON,LAT,DTTM,HEADING,CALL_SIGN,vesselType&lt;/SPAN&gt;]
&amp;nbsp; writer.writerow(data)&lt;/PRE&gt; &lt;BR /&gt;I'm guessing it should be something like:&amp;nbsp; &lt;BR /&gt;data = [ID,LON,LAT,str_date,HEADING,CALL_SIGN,vesselType&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks. I did note that discrepency. It has been corrected.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:31:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162290#M5467</guid>
      <dc:creator>JimKrist</dc:creator>
      <dc:date>2021-12-11T08:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162291#M5468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks to all for your responses. Problem has been solved by splitting date and time and then concatenating in text field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp; dt = RX_DTTM[:19]
&amp;nbsp; dtime = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
&amp;nbsp; str_date = dtime.strftime('%Y-%m-%d %H:%M')
&amp;nbsp; DT,TM = str_date.split(' ',1)
&amp;nbsp; data = [ID,LON,LAT,DT,TM,vesselType]&amp;nbsp; 
&amp;nbsp; writer.writerow(data)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When geocoding I use arcpy.ConcatenateDateAndTimeFields_ta to process DT, TM into DTTM:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;filenum = 0
path = raw_input('Enter the full path name for input files (ex. c:\\input\): ')
datapath = raw_input('Enter the path for the output directory (ex. c:\\output\): ')
dirList=os.listdir(path)
dirList.sort()
for fname in dirList:
&amp;nbsp; if not fname.startswith('schema'):
 filenum += 1
 filename = path + fname
 shp = datapath + str(filenum) + 'output.shp'
 try:
&amp;nbsp; arcpy.MakeTableView_management(filename,'View')
&amp;nbsp; arcpy.MakeXYEventLayer_management('View','LON','LAT','Layer')
&amp;nbsp; arcpy.CopyFeatures_management('Layer', shp)
&amp;nbsp; arcpy.CheckOutExtension('tracking')
&amp;nbsp; arcpy.ConcatenateDateAndTimeFields_ta(shp, 'DT', 'TM','DTTM')
&amp;nbsp; arcpy.DefineProjection_management(shp, coord)
&amp;nbsp; arcpy.FeatureClassToGeodatabase_conversion([shp], geodb)
&amp;nbsp; print 'File ' + filename + ' has been geoprocessed'
 except IOError:
&amp;nbsp; print 'ERROR: ' + filename&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note: I did have to create a specific schema.ini file in the directory (explaining the if not fname.startswith('schema'): ignore file clause) to ensure all fields from the CSV files were assigned data type. One entry was required for each file in the directory as my investigation found that wildcards could not be used in the .ini file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
[1_output.csv]
Format=CSVDelimited
Col1=ID Long
Col2=LON Double
Col3=LAT Double
Col4=DT Text
Col5=TM Text
Col18=VesselType Text
[2_output.csv]
Format=CSVDelimited
Col1=ID Long
Col2=LON Double
Col3=LAT Double
Col4=DT Text
Col5=TM Text
Col6=VesselType Text&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could prove challenging as we will have hundreds of input files after parsing the large (600GB) CSV files.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:31:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162291#M5468</guid>
      <dc:creator>JimKrist</dc:creator>
      <dc:date>2021-12-11T08:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162292#M5469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Time to move to loading the data and transforming it with FME (otherwise disguised as the Data Interoperability Extension)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;No scripting required, much better performance, easy to debug, the ETL standard tool for good reason.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 07:22:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162292#M5469</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2012-11-13T07:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime from CSV file</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162293#M5470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Could prove challenging as we will have hundreds of input files after parsing the large (600GB) CSV files.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;You could automate the creation of your .ini file (if it's simply changing the csv filename by an increasing number):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;iniFile = open(r"PATH_TO_YOUR_INI_FILE",'w')

numbers = range(1,100)

for i in numbers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; iniFile.write("[" + str(i) + "_output.csv]\n\
Format=CSVDelimited\n\
Col1=ID Long\n\
Col2=LON Double\n\
Col3=LAT Double\n\
Col4=DT Text\n\
Col5=TM Text\n\
Col6=VesselType Text\n")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:31:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/datetime-from-csv-file/m-p/162293#M5470</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T08:31:15Z</dc:date>
    </item>
  </channel>
</rss>

