3

I have two columns called "LC" and "LC Datum".

"LC" contains text value's like 2015, 2016 and so on. These are actually years and need to be converted/transfered to another column called "LC DATUM", where the text value will be a date year value.

When I try to go in the Attribute table into the Field calculator. And then into the Column "LC Datum" and try to set the expression "LC" in the "LC Datum" Column it gives the value NULL. This is strange because I clearly see a result of the execution in the calculator window. I assume I need to do an extra conversion of my data. But how do I do this?

Edit: As the last thing I also need to note that there are null value's in my LC column.

  • 1
    Expression year("LC") could work? – Kazuhito Apr 11 '17 at 11:18
  • No It does not work for me because the I says the expresion is not vallid. It cannot convert it to Date Time format... – ThunderSpark Apr 11 '17 at 12:48
  • You are right, sorry. Only way I can think of is (1) create or update "LC_Datum" field by an expression to_date(concat("LC", '-01-01')) and then (2) Open Layer Properties | Fields and click on [Text Edit] to change the widget to Date/Time which allows custom to yyyy format. – Kazuhito Apr 11 '17 at 13:44
  • ...Um your case I think will work but the problem is that some value's in LC column are NULL causing an error to occur. How do i get past that then? – ThunderSpark Apr 11 '17 at 14:16
  • 2
    @Kazuhito - Kindly post your comment as an answer but replace to_date(concat("LC", '-01-01') with to_date("LC" || '-01-01') since you pretty much got it right :) – Joseph Apr 12 '17 at 9:29
2

With help from @Joseph , this is the proposed steps.

  1. In the Field Calculator, create or update "LC_Datum" field by an expression to_date("LC" || '-01-01'). Close the Attribute table.

  2. Open Layer Properties and select Fields tab. Click on [Text Edit] of the LC_Datum to change the widget to Date/Time which allows Widget display option to custom and manually set it to yyyy format.

As data type of "LC_Datum" was set to Date, it expected date formatted inputs like 2015-01-01, and rejected 2015.

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.