Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have two date fields dd.mm.yyyy with a start and an end date in my attribute table. Now I want only to extract the years from these fields to new fields. So I created another field, and used year_start_date = DatePart ( "YYYY", [Start_date] ) in the field calculator.

But the result is a complete date (dd.mm.yyyy) more than 100 years ago.

Just to test, I created a new field and added with the function Now() the actual date (13.05.2014) and tried again to use year_start_date = DatePart ( "YYYY", [Start_date] ) and I got "06.07.1905" as a result.

What am I doing wrong? Is there another way to do this? I use ArcGIS 10.2.

share|improve this question
1  
Is your field year_start_date a date field or an integer field? –  Michael Miles-Stimson May 12 at 22:45
    
All of these fields are date fields, not integer or string. –  Peter May 12 at 22:49
    
There's your problem there, DatePart returns an integer and putting that into a date field is bad.. the date is stored as long date format as seconds from some point (possibly 1905); I'm sure there's more explanation about that available. You need to turn your integer back into a date to put it into a date field, here's something that might help explain stackoverflow.com/questions/2623156/… –  Michael Miles-Stimson May 12 at 22:54
    
I just tried it. It works. You're great!! Thanks :-) –  Peter May 12 at 23:00
    
Awesome! I'll turn that into an answer to neaten up this post. –  Michael Miles-Stimson May 12 at 23:01

1 Answer 1

up vote 3 down vote accepted

DatePart returns an integer and putting that into a date field is bad.. the date is stored as long date format as seconds from some point (possibly 1905); I'm sure there's more explanation about that available, but's lets just accept that that's the way that it is.

You need to turn your integer back into a date to put it into a date field, here's something that might help explain http://stackoverflow.com/questions/2623156/how-to-convert-the-integer-date-format-into-yyyymmdd

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.