2

I'm working on a Druapl 8 project and I'm trying to execute a migration which serve to import content of a basic content type, the content type has a field of type Date and the associated field in my CSV source file has the format "dd-mm-yyyy", I used the 'format_date' plugin to migrate the date as bellow:

process:
  field_date:
    plugin: format_date
    from_format: 'd-m-Y'
    to_format: 'd/m/Y'
    source: Date

with field_date is the machine name of my content type date field, and Date is the field name in my csv file: source.csv

title,Date
title 1,12-01-2017
title 2,13-03-2018

After migration the content has been created as it should but with date value as bellow: enter image description here

Any help please!

2
  • 2
    Let try replace to_format: 'd/m/Y' to to_format: 'Y-m-d'.
    – MrD
    Sep 14, 2018 at 15:12
  • 2
    Ok, let me write an answer and explain why.
    – MrD
    Sep 14, 2018 at 15:34

1 Answer 1

3

You need to convert source date from d-m-Y to Y-m-d

process:
  field_date:
    plugin: format_date
    from_format: 'd-m-Y'
    to_format: 'Y-m-d'
    source: Date

because default field Date use format Y-m-d to store date. and Y-m-d\TH:i:s to store datatime.

Form display just show default pattern (mm-dd-yyyy) of html5 input date

1
  • 1
    Yeah, the migrate plugins are a bit generic for source/destination, and the format_date plugin doesn't assume a datetime destination, just something that needs a formatted date.
    – mpdonadio
    Sep 15, 2018 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.