7

I have a shapefile with date in a string field. I create a new field with date type and use the calculator to make the conversion. But the result only provide the date part, the time part is removed. Even when the preview show the correct conversion.

Here you can see the original string field time and the result date time2. And the use of the conversion function to_datetime() and the preview result at the end

enter image description here

If you go to the layer properties you can change the edit mode to date/time. Then if go to the data and try to edit time2 you get the current date/time. So is possible save date and time in the same field. But the update tool still doesn't work as expected

enter image description here


As J.R said. Even when you can change QGIS edit to allow Date/Time the save to shapefile will discard the time.

3
  • 1
    The Date field only allows you to store up to 10 characters, enough for YYYY-MM-DD. If you want to also store the time, use a String field instead and set a larger character length value :)
    – Joseph
    Commented Jan 9, 2018 at 16:06
  • @Joseph Im confused, the file is a shapefile from esri, and my understanding is date field can store date and time desktop.arcgis.com/en/arcmap/10.3/manage-data/geodatabases/… Commented Jan 9, 2018 at 16:45
  • 2
    Esri didn't create the dBase format (Ashton-Tate did, in the early 1980s; at the time, they were considered forward-thinking for using four bytes to store years). If you want second-resolution time datatype, you need to use a geodatabase format (Personal, File or Enterprise)
    – Vince
    Commented Jan 9, 2018 at 22:28

1 Answer 1

10

As joseph said in comment you can't store date and time in a single field of a shapefile, you could :

-use a string field (as Joseph said)

-use two field (one for date and one for time...)

-use another file format that support DateTime fieldtype to store your data

9
  • Im confused, the file is a shapefile from esri, and my understanding is date field can store date and time desktop.arcgis.com/en/arcmap/10.3/manage-data/geodatabases/… Commented Jan 9, 2018 at 16:46
  • 2
    you should chek this ESRI page resources.esri.com/help/9.3/ArcGISDesktop/com/Gp_ToolRef/… about shapefile limitation it state that it is not possible to store date and time in the same field. Also I try to replicate your edit trick but the time is remove from the field afer saving the edit....
    – J.R
    Commented Jan 9, 2018 at 17:05
  • 5
    NOBODY should use a geodatabase. Use a standard format like geopackage or spatialite instead.
    – ndawson
    Commented Jan 9, 2018 at 21:06
  • 1
    @ndawson What you mean? That is the standard for esri. Commented Jan 10, 2018 at 13:58
  • 2
    If you're looking for interoperability with qgis then geodatabase is a bad move. While qgis can open them, it's read only and much slower than the alternative formats.
    – ndawson
    Commented Jan 10, 2018 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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