can anyone tell me how to add an attribute of type Date during a shapefile creation?

For Integer works fine using the following code:

Layer1.CreateField(ogr.FieldDefn('NumberIndv', ogr.OFTInteger))

The same for String and Real, changing the type to ogr.OFTString or ogr.OFTReal.

What should I use for Date type?

  • 1
    Yes, indeed. Sorry, I'm a newbie in GDAL/OGR and in fact I found this link: gdal.org/ogr__core_8h.html#a787194bea637faf12d61643124a7c9fc.
    – Falcoa
    Mar 31, 2016 at 12:57
  • No problem and don't worry, you're now more experienced in GDAL/OGR than I am! But will post the comment as an answer for the convenience of others :)
    – Joseph
    Mar 31, 2016 at 13:02

1 Answer 1


You could use ogr.OFTDate to create a new date-type field so your line would look something like:

Layer1.CreateField(ogr.FieldDefn('DATE', ogr.OFTDate))

This and other OGR field types are documented in



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.