4

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.

  • 1
    Is your field year_start_date a date field or an integer field? – Michael Stimson May 12 '14 at 22:45
  • All of these fields are date fields, not integer or string. – Peter May 12 '14 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 Stimson May 12 '14 at 22:54
  • I just tried it. It works. You're great!! Thanks :-) – Peter May 12 '14 at 23:00
  • Awesome! I'll turn that into an answer to neaten up this post. – Michael Stimson May 12 '14 at 23:01
4

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 https://stackoverflow.com/questions/2623156/how-to-convert-the-integer-date-format-into-yyyymmdd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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