2

I want to change the date format with different date formats in the attribute table to the one format which is fitting for the Time manager. Does it work with the Field Calculator?

For example 12.August 2020 and I want to have 2020-08-12. Does anyone know how this works?

4
  • 1
    a couple more tags wouldn't hurt either Sep 22, 2020 at 13:22
  • Its QGIS 3.4...
    – Andrea H.
    Sep 22, 2020 at 13:52
  • I want to choose some other but it doesnt work :/ sorry
    – Andrea H.
    Sep 22, 2020 at 13:53
  • Take a look at format_date() expression ;)
    – MrXsquared
    Sep 22, 2020 at 14:00

1 Answer 1

1

To convert your example string (which I assume is not actually a date value):

to_date('12.August 2020', 'd.MMMM yyyy')

This will give a datetime value.

To convert it directly to the new format:

format_date(to_date('12.August 2020', 'd.MMMM yyyy'), 'yyyy-MM-dd')

Producing 2020-08-12

You will need to substitute your field name for '12.August 2020' for this to work, i.e.:

format_date(to_date("myDate", 'd.MMMM yyyy'), 'yyyy-MM-dd')

See here for information on date formats and string conversion, or look at the help in the field calculator for format_date().

5
  • Sorry, but it doesnt work with this string...is something wrong with the command?
    – Andrea H.
    Sep 22, 2020 at 17:23
  • Can you help me with that string please?
    – Andrea H.
    Sep 23, 2020 at 12:26
  • Did you try to copy and paste exactly what I wrote here? I tested this in QGIS 3.14 and 3.10; if you're on 3.4 perhaps there is some functionality missing.
    – Simbamangu
    Sep 23, 2020 at 17:46
  • Ive try it with 3.4...thats why its not working...
    – Andrea H.
    Sep 23, 2020 at 17:57
  • @andrea Any reason you can't use the recent long-term-support version?
    – Simbamangu
    Sep 24, 2020 at 5:19

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.