2

I try to import a CSV file with Drupal 8 Migrate. One column contains a year value which I want to convert to a Drupal date field.

I try to do that with the following process statement using format_date plugin from Migrate Plus but something goes wrong:

  process:
    field_fecha:
      plugin: format_date
      from_format: 'Y'
      to_format: 'Y-m-d\TH:i:s'
      settings:
        validate_format: false
      source: year

I'm not sure if Y is allowed as from_format value. But I also don't know what standard value uses Drupal 8 date field and what to put as to_format value.

  • That plugin is provided by core (see drupal.org/node/2829381). Do you get any errors when you try this? – mpdonadio Nov 11 '17 at 18:10
  • Just fails silently, doesn't show any errors but field is empty. Does the to_format depend on Drupal locale settings or do I always have to use 'Y-m-d\TH:i:s'? – geraldo Nov 16 '17 at 16:30
2

Just found out that to_format value is the problem. Setting it to 'Y-m-d' works fine and imports the year value as date putting month and day to values of today. So actually to get specific day and month added to year value, this code works fine:

process:
    field_fecha:
      plugin: format_date
      from_format: 'Y'
      to_format: 'Y-01-01'
      source: year

Probably that's because I defined the date field as "date only". For "date and time" fields 'Y-m-d\TH:i:s' should work fine.

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.