1

I am trying to migrate a datetime field from csv file but only few are being migrating and other are being failed.I am using migrate

I have created two datetime fields called as Activation Date and Expiry Date in article content type. Attached field type images for reference.

I am writing a custom migration yml file to migrate data from csv file. But only the date values from id 6-10 are being imported but not the date values from 1-5 .

While import I am getting error stating article_csv_import Migration - 5 failed.

I have included sample data and yml file for reference.

Can anyone please let me know what causing the first 5 dates import failing ? Any pointers for a way to debug migration process is greatly appreciated.

migration_examples/migrations/article_csv_import.yml

id: article_csv_import
label: Import Articles
migration_group: default
migration_tags:
  - Article CSV Migration

source:
  plugin: 'csv'
  # Full path to the file.
  path: public://subscription-list-small-copy.csv
  # Column delimiter. Comma (,) by default.
  delimiter: ','
  enclosure: '"'
  header_offset: 0
  ids:
    - id
  fields:
    0:
      name: id
      label: 'Id'
    1:
      name: title
      label: 'Title'
    2:
      name: body
      label: 'Post body'
    3:
      name: field_activation_date
      label: 'Activation Date'
    4:
      name: field_expiry_date
      label: 'Expiry Date'
process:
  title: title
  body: body
  #activation date of the account.
  field_activation_date:
    -
      plugin: format_date
      from_format: Y-m-d H:i:s
      to_format: 'Y-m-d\TH:i:s'
      from_timezone: 'America/Managua'
      to_timezone: 'UTC'
      source: field_activation_date
  # expiry date of the account.
  field_expiry_date:
    -
      plugin: format_date
      from_format: Y-m-d H:i:s
      to_format: 'Y-m-d\TH:i:s'
      from_timezone: 'America/Managua'
      to_timezone: 'UTC'
      source: field_expiry_date
  type:
    plugin: default_value
    default_value: article

destination:
  plugin: entity:node

Sample CSV Data : subscription-list-small-copy.csv

id,title,body,field_activation_date,field_expiry_date
1,Title 1,Body 1,2012-12-22 2:36:03,2013-01-03 0:00:00
2,Title 2,Body 2,2013-08-16 0:00:00,2013-09-15 0:00:00
3,Title 3,Body 3,2013-09-14 0:00:00,2013-10-14 0:00:00
4,Title 4,Body 4,2014-04-08 0:00:00,2014-04-07 23:59:59
5,Title 5,Body 5,2014-09-30 0:00:00,2015-03-29 11:00:00
6,Title 6,Body 6,2014-12-09 12:29:00,2015-01-09 12:29:00
7,Title 7,Body 7,2014-12-31 11:08:00,2015-06-26 23:59:59
8,Title 8,Body 8,2015-02-25 19:12:00,2015-08-10 23:59:59
9,Title 9,Body 9,2015-03-01 11:19:00,2015-02-28 23:59:59
10,Title 10,Body 10,2015-03-02 18:01:00,2015-08-20 23:59:59

image-1 image-2

1 Answer 1

3

from_format: Y-m-d H:i:s means hours with leading zeroes, but there are no leading zeroes in your source. Use from_format: Y-m-d G:i:s (capital G) for 24-hour-format without leading zeroes

see https://www.php.net/manual/function.date.php

1

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.