2

I have a vector layer of almost 13000 lines I need to split depending on one of the field, in the format "DateTime" (YYYY-MM-DDTHH:MM:SSS). In total there is 254 unique values in this field.

It seems that QGIS don't allows splitting up a layer in this format. I have tried creating a new field in the Field calculator, and also the tool Refactor fields with no luck, only getting in return the Date, or NULL in the attribute table. I have thought about the regexp_replace function in the Field Calculator, but I don't know how to arrange it to only give me the numbers as output in the new field.

I don't need to have the date and time in the format YYYY-MM-DDTHH:MM:SSS, but I do need to have at least YYYYMMDDHHMM, preferably in integer format, so I can manage to split up the vector layer.

I am still new to QGIS.

1
  • 2
    What do you mean by split up? What does not work for you?
    – Ian Turton
    Commented Oct 16, 2022 at 14:25

1 Answer 1

3

If by "splitting up", you mean creating a new layer per unique attribute value, there is the tool 'Split vector layer'. It will do what you need without having to convert the date field. However, you should consider whether creating 254 layers is really appropriate.

If you want the date as an integer without the seconds displayed, you can use an expression like this on your DateTime field:

to_int(format_date("datetime", 'yyyyMMddHHmm'))

See the help panel of the Field Calculator for explanation of the format notation.

Example output:

16/10/2022 17:14:23   --->  202210161714

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.