I guess the python OGR API has a way to define a datetime field and store data in it (its defined in the OFRFieldType
enum. You have to use the OFTDateTime
(or OFTDate
or OFTTime
) type defined by OGR.
So you can do something like :
date_field = ogr.FieldDefn("date", ogr.OFTDateTime)
your_layer.CreateField(date_field)
then you can set the value for a feature by passing your date as a string:
feature = ogr.Feature(your_layer.GetLayerDefn())
feature.SetField("date", "2014-05-14 17:42:18")
The result may depend on your output data structure (if it defines/supports a date time type) and on the desktop GIS software you are using to display them.
EDIT : But I tested to write a shapefile like this, then open it in QGIS; the date field was properly recognized as a QDate
field, and as you say the time is not showing so I looked in the .dbf
file and the time part doesn't seems to have been written.