1

In my Drupal 7 site, the date is stored in the database as 2020-08-10 00:00:00.

When I migrate those dates without any formatting (field_blog_post_date: field_blog_post_date), the date is migrated into the Drupal 8 table with the same exact formatting. However, it doesn't show when a node is viewed.

I tried to use a format_date plugin.

field_blog_post_date: 
  plugin: format_date
  source: field_blog_post_date
  from_format: 'Y-m-d H:i:s'
  to_format: 'Y-m-d'

When I use it, it causes the following error.

DateTime::createFromFormat() expects parameter 2 to be string, array given
DateTimePlus.php:251

8
  • Side question, why are you using field_blog_post_date rather than the node's created date?
    – No Sssweat
    Oct 22, 2020 at 20:19
  • its an additional date which indicates when they want it to be posted.
    – Diana
    Oct 22, 2020 at 20:22
  • Does the D8 database value look as expected? Or does it fail to import?
    – No Sssweat
    Oct 22, 2020 at 20:35
  • it imports but with this structure.2020-08-10 00:00:00 in the database. but. doesn show upon viewing the. content in the edit mode
    – Diana
    Oct 22, 2020 at 21:06
  • Since it's Date only, it needs to be 2020-08-10 in the D8 db, otherwise it won't display. For some reason its failing to re-format.
    – No Sssweat
    Oct 22, 2020 at 21:12

2 Answers 2

3

Also from https://www.drupal.org/project/drupal/issues/2923723#comment-13141671

field_blog_post_date:
    plugin: sub_process
    source: field_blog_post_date
    process:
      value:
        plugin: format_date
        from_format: 'Y-m-d H:i:s'
        to_format: 'Y-m-d'
        source: value

Should work

2

this worked! found the answer here https://www.drupal.org/project/drupal/issues/2923723#comment-12343660

 field_blog_post_date: 
        plugin: iterator
        source: field_blog_post_date
        process:
          value:
            plugin: substr
            source: value
            start: 0
            length: 10

Your Answer

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

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