I have imported a table from Excel that has one field (StartDate) to hold dates. When I imported the table it into ArcMap, the date values in that field changed from DD/MM/YYYY to a 5-digit number, e.g. 3/3/2010 now shows as 40240. In ArcCatalog, upon inspection the properties of this field is now a string data type. This 5 digit number is a result of stripping away the Excel formatting and revealing the true absolute, or serial date value of this particular date.
Therefore, I want to use the field calculator to convert the 5-digit string values back into a readable date format, using VB.
I have created a new field (StartDateDT) (formatted to DATE) to house the converted (5-digit to Date) date values.
Using ArcMap 10.2.2 Standard license.
2 Answers 2
Open the Field Calculator, set to use Python Parser, and enter the following expression:
datetime.datetime(1899, 12, 30) + datetime.timedelta(days= !StartDate! )
There is potential if you have dates between 1 Jan 1900 and 1 March 1900 that this will give an incorrect value due to Excel thinking 1900 was a leap year, but for anything after those dates this should work.
It is possible to work around the above bug, but if you don't have those dates then I wouldn't bother.
Credit: Code for this answer taken from Parsing serial date in ArcGIS for Desktop?
-
That did the trick! The only thing I had to change is to make sure that the serial date value is LONG INT and not TEXT or DOUBLE. But otherwise, it worked perfectly. THANKS so much for your help!pelampe– pelampe2016年04月02日 16:49:59 +00:00Commented Apr 2, 2016 at 16:49
An alternative..Definitely not as eloquent.. but it's what I came up with to solve the same issue.. using Field Calculator and the following expression in python.
def convExcelDate(inp):
inp = float(inp)
Yearconv = str(1900+int(inp/365.25))
DaysRemconv = inp-((int(inp/365.25))*365.25)
Month = 1
for M in [31,28,31,30,31,30,31,31,30,31,30,31]:
if DaysRemconv > M:
DaysRemconv = DaysRemconv- M
Month = Month + 1
returnVal = str(int(DaysRemconv))+'/'+str(Month) +'/'+ str(int(float(Yearconv)))
return returnVal
and calling the field value:
convExcelDate(!YourFieldHere!)
Explore related questions
See similar questions with these tags.
40240
is a date,0.625
is a time, and40240.625
is a date + time (3/3/2010
,15:00:00
, and3/3/2010 15:00:00
, respectively)