4

I have a shapefile with polygons. Each polygon contains a date (fully written in text, for example: '2 june 2018') in the attribute table. This field is format 'text'. Now, I would like to convert these fields / this column to a new column with the dates written in numbers (for example '02/06/2018'). The new fields have to be formatted as 'date'.

Does anybody know how to do this quickly in the field calculator using a formula?

Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Sep 5, 2023 at 8:09
1

1 Answer 1

5

First I'd like to note that only the international date format is of type "date": yyyy-mm-dd. All other types are just representations of this date and depend e.g. on your settings about locales in QGIS. You can change these in Settings --> Options --> General. That being said, you can use this expression:

 to_date('2 june 2018', 'd MMMM yyyy', 'en')

respectively replace the date with your field.

Taras
35.7k5 gold badges77 silver badges151 bronze badges
answered Sep 5, 2023 at 8:16
1
  • Hi MrXsquared, works perfectly! Although I changed the 'en' to 'nl', because the names of the months are written in Dutch. Works! Thanks!! Commented Sep 5, 2023 at 11:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.