CSV input not including time with date

634
5
Jump to solution
03-01-2022 04:20 PM
ccowin_odfw
Occasional Contributor

Hello,

I have big script (in a python toolbox) that can take in GPS Collar data from several manufacturers and spits out a feature class for review before it is added to the main database. One of the manufacturers outputs their data in a csv. So I'm just doing a table to table conversion and then going through the rest of the script. The issue is that only the date is coming through and leaving the time for some reason. I don't think it would be too onerous to split up the column in the csv before it was imported (I have another CSV but their date and time come separated and I combine them into 1), but it seems like this shouldn't be a problem in the first place as I'm using a field calculator to just input the entire column into the feature class:

arcpy.management.CalculateField(output_path, 'UTC',
expression='!Date___Tim!',
expression_type='PYTHON 3',
code_block="""""",
field_type='DATE'
)

Also tried converting it to a string, but it seems to be losing the time when the CSV is converted to the table, but I have no idea why that would be.

The format in the CSV is:

%m/%d/%Y %H:%M:%S

 Thanks!

0 Kudos
1 Solution

Accepted Solutions
RhettZufelt
MVP Frequent Contributor

I see the same issue until I add a column title for the missing column, and remove the invalid column names (spaces, special characters, etc).

 

If I ensure ALL the fields have a name, and that name is a single word, then it converts to table as expected with date and time in the fields.

 

RhettZufelt_0-1646239679948.png

 

If you run the Table to Table GP tool in Pro, it appears as if it "fixes" these issues on the fly.  With the python code, however, I had to fix the column name issues before it worked.

R_

 

View solution in original post

5 Replies
JayantaPoddar
MVP Esteemed Contributor

Could you share a sample CSV?



Think Location
0 Kudos
ccowin_odfw
Occasional Contributor

Sure, 

In the original there would be a latitude and longitude that I've removed to satisfy our data privacy standards.

0 Kudos
RhettZufelt
MVP Frequent Contributor

I've noticed the same behavior in the Table To Table GP tool in pro if I try .csv or .xls.

However, if I open the csv in Excel and save as .xlsx, then the date/time imports as expected.

R_

0 Kudos
RhettZufelt
MVP Frequent Contributor

I see the same issue until I add a column title for the missing column, and remove the invalid column names (spaces, special characters, etc).

 

If I ensure ALL the fields have a name, and that name is a single word, then it converts to table as expected with date and time in the fields.

 

RhettZufelt_0-1646239679948.png

 

If you run the Table to Table GP tool in Pro, it appears as if it "fixes" these issues on the fly.  With the python code, however, I had to fix the column name issues before it worked.

R_

 

ccowin_odfw
Occasional Contributor

Awesome will give that a shot!

0 Kudos