I have an attribute column that has a string datetime and I want to convert that to a date column. I first attempted to simply add the time column in an expression, and I only got the year/month/date, but I wanted the time as well. So I first converted it the string to a new column with format_date(), to clean up the format, and then I went ahead and used to_datetime() to convert the string into the date column. It shows up fine in the Expression dialogue but then doesn't add the hour/minute/seconds.

What am I overlooking?

Using QGIS version 3.16.1-Hannover on Windows

enter image description here

  • Which one is your source column? What file format is it and which datatype did you choose? – MrXsquared Jan 3 at 23:31
  • It was because I converted a CSV to a shapefile, so problem solved. Shapefiles apparently don't store date and time in same field. – DrewGIS Jan 4 at 0:35

You probably use shapefile format. Otherwise it should have worked.

According to the documentation shapefile format doesn't store date and time in the same field. You need to add date and time to seperate columns or use other format like GeoPackage.

  • You know that was it, I didn't know that about shapefiles. I converted from a CSV to a shapefile and it went all wonky. I'm using a geopackage now and it works perfectly. – DrewGIS Jan 4 at 0:33
  • I have just learned that after your question. :) I have not used date and time in shapefile so far. – Kadir Şahbaz Jan 4 at 0:53

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.