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!

  • 1
    Let try replace to_format: 'd/m/Y' to to_format: 'Y-m-d'. – MrD Sep 14 at 15:12
  • it works just great thanks dude! :) – Brahim Khouy Sep 14 at 15:33
  • 1
    Ok, let me write an answer and explain why. – MrD Sep 14 at 15:34
up vote 2 down vote accepted

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

  • 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 at 20:41

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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