3

I am trying to convert a string column that contains date and time values into a datetime column in QGIS. The format of the string column is (yyyy-mm-dd hh:mm:ss). I write the expression as to_datetime("DateTime", 'yyyy-mm-dd hh:mm:ss'), but get an error message saying that I cannot convert that specific column to datetime. As far as I know, the layer is saved as a GeoPackage.

enter image description here enter image description here enter image description here

2
  • Can you show us the full DateTime field? At the moment the screenshot cuts it off halfway. JGH's solution below works for me. Commented Dec 7, 2023 at 4:48
  • Yes, I have added it to the original post.
    – Abdy
    Commented Dec 7, 2023 at 11:19

1 Answer 1

8

The doc says mm is for minutes, MM for months

Try with to_datetime("DateTime", 'yyyy-MM-dd hh:mm:ss')

enter image description here

3
  • It still gives me the same error /:
    – Abdy
    Commented Dec 6, 2023 at 22:31
  • 2
    Make sure the - and the space are exactly the same characters in the input and in the expression (copy-paste them from one of the record)
    – JGH
    Commented Dec 7, 2023 at 9:01
  • 2
    There was an extra space in my original column, thank you so much!
    – Abdy
    Commented Dec 7, 2023 at 11:21

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