4

I save date from database's timestamp to shapefile date attribute. For example, I took from database [2031,10,31] and set it to '31.10.2031' at shapefile using python's shapefile.py as sh:

self.sh.field('Exp_date', 'D', 10)
....
valueString = date(*tuple(date_value)).strftime('%d.%m.%Y')
print valueString
>>>31.10.2031
self.records.append(valueString)
... # set other fields
self.sh.record(*self.records)

But when I open the result at ArcGIS 10.1 I see all years converting to 1930-2029 (as system Date&Time settings). So when I open the dbf at shapefile directory, I see the DD.MM.YY-format dates. But at DBF specification 'D' fields are YYYYMMDD format.

Is there a way to save full year at dbf?

  • This isn't a characteristic of the shapefile format (or dBase), but of the shapefile.py implementation. Dates are encoded YYYYMMDD in the dBase III+ record construct ('%Y%m%d' in strftime). There is no space for delimiters in the 8 character buffer. – Vince Nov 8 '16 at 12:17
  • 1
    @Vince Thanks a lot! I set 'D', 10, not 8 symbols, but D saved 8 symbols. Now I change strftime('%d.%m.%Y') to strftime('%Y%m%d') and date stay clear. Can you write your tip as answer? – Mae Nov 8 '16 at 12:50
4

Unlike a number of data formats of its time, dBase-III was "Y2K" compliant (it used the extra bytes necessary to store the actual year in four digits). Unfortunately for modern uses, this came at the cost of not storing time values at all.

The dBase field buffer for D type values utilizes eight characters, in the format YYYYMMDD (delimiters would have only increased the storage requirement 25%).

It appears that the Python interface you are using does not validate or otherwise enforce proper date value formatting, so you are required to provide the exact date format used in the transfer buffer. In strftime syntax, that would be to use the format string '%Y%m%d'.

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.