Converting numeric time values into date format

962
13
Jump to solution
12-16-2019 07:20 PM
AustinReeves
New Contributor II

Hello, 

I have run into a little problem regarding the formatting of dates within a ArcPro table. First off, the table is originally a .xlsx and has been converted using the "excel to table" tool. The original excel table has a date field with values in the format of "12/23/1998 14:40" and has upon using the tool, has been converted into the 5-digit numeric date scheme. These numeric dates have decimals i.e. "26507.6875" and is due to what I assume to be the time of day. I have found this thread Date field in Excel to Table tool , but upon trying the code I get the standard "999999" message (unexpected error). Any other suggestions on how I can get the dates back to the regular format? Thanks!

-Austin

1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

from

Work with Microsoft Excel files in ArcGIS Pro—Excel | ArcGIS Desktop 

If you have cells with numeric data, dates, and so on, ensure that the content is consistently formatted—in other words, make sure all numeric data is actually numeric. If there are other types of data in those rows, the field is converted to text when the table is opened in ArcGIS Pro.

They fail to mention that "blanks" can break the "consistently" rule.

No cell should go empty!!  There should be a huge warning flash onscreen when blanks are encountered

If you are working in Pro tables from scratch....

/blogs/dan_patterson/2019/11/28/the-solution-to-null-in-tables 

Or know some python

/blogs/dan_patterson/2018/12/13/excel-arrays-tables-in-arcgis-pro 

View solution in original post

13 Replies
DanPatterson_Retired
MVP Esteemed Contributor

You should probably show your expression, especially to check on how you truncated your time from the string since the example in your thread was for dates, not datetime

AustinReeves
New Contributor II

The expression I used was: datetime.datetime(1899,12,30) + datetime.timedelta(days = int(!Sample_Date_Time!))

My field containing the dates is the "Sample_Date_Time" and the rest was derived from that thread I linked. I'm not too familiar with python yet so would not be too sure where or what to change about this code. 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

What Dan said. In the thread you reference I apply int() to a string. Is your 'decimal day' numeric or string?

can't wait to retire....
0 Kudos
AustinReeves
New Contributor II

By 'decimal day' you are referring to the format that is being created in the ArcPro table (26507.6875) correct? I would assume this is a string as it contains decimals. 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

26507.6875 could be  string; could be a float; could be a double.....

can't wait to retire....
0 Kudos
AustinReeves
New Contributor II

Alright, I have looked in the fields editor and it is listed as a text data type, with the number format as numeric. This is what the original date format is being converted to via the "excel to table" tool. Thanks again for the help!

0 Kudos
JoeBorgione
MVP Esteemed Contributor

As I recall, when the excel table runs in an excel date field, as long as all of the fields have values it will bring them over as date fields. But... if any of those excel fields are empty, it converts the whole lot of them into the Microsoft date index and types the field as text.

can't wait to retire....
AustinReeves
New Contributor II

That is correct in that the excel table I'm working from has missing values for various rows. However, it would be quite tedious to sort through all 80,000 and something samples ha! I wonder of there's an excel function to weed these out...

0 Kudos
AustinReeves
New Contributor II

Have now filtered out all blanks and will see how this new table converts to ArcPro!

0 Kudos