Following the already existing solution at https://www.drupal.org/node/2820490 , i have tried the FormatDate Plugin indicated but none of them seem to work for me when i try to migrate my date field from drupal 7 to drupal 8. Any idea what why

here is my code

langcode: en
status: true
dependencies: {  }
id: remark
class: Drupal\migrate\Plugin\Migration
field_plugin_method: null
cck_plugin_method: null
migration_tags: null
migration_group: null
label: 'Student Article'
source:
  plugin: d7_node
  node_type: student_article_page
process:
  type:
    plugin: default_value
    default_value: student_article
  nid: tnid
  vid: vid
  langcode:
    plugin: default_value
    source: language
    default_value: und
  title: title
  uid: node_uid
  status: status
  created: created
  changed: changed
  promote: promote
  sticky: sticky
  revision_uid: revision_uid
  revision_log: log
  revision_timestamp: timestamp
  comment_node_student_article_page/0/status: comment
  body:
    plugin: get
    source: body
  field_student_article_date/value:
    -
      plugin: extract
      source: field_article_date
      index:
        - '0'
        - value
    -
      plugin: format_date
      from_format: 'Y-m-d H:i:s'
      to_format: 'Y-m-d\TH:i:s'
      timezone: 'GMT'
destination:
  plugin: 'entity:node'
migration_dependencies:
  required:
    - upgrade_d7_user

Can someone please tell me why the body field is able to migrate but the "field_student_article_date" is not able to migrate

Comments

docans created an issue. See original summary.

docans’s picture

This Solution worked for me for migrating a single Date field

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

Credit to http://data.agaric.com/migrating-date-field-content-drupal-8

cilefen’s picture

Priority: Critical » Normal

This is not critical.

osopolar’s picture

Have you tried field_student_article_date: instead of field_student_article_date/value:? In my example it works fine without /value for a d6 to d8 migration. There are other examples with /value, maybe the difference is that one is with and the other one without end date. Otherwise you may use xdebug to debug your migration and see what happens.

docans’s picture

I tried every options possible from the previous ticket. I took away the /value and it didn't work for me. The solution i posted above is the only one that works in Drupal 8.4.2

safetypin’s picture

I'm experiencing the same issue.

The default migration moves all field data except for dates. In both drupal installs (d7 & d8), the fields are configured to only collect year/month/day without an end date.

Using the substr plugin from #2 worked.

safetypin’s picture

I happened to look at my D8 database, and it looks like the date field data is actually being migrated, but for some reason the field data is not being displayed either on the node (Full display node) or in the node edit form.

docans’s picture

Use the solution at #2. It will work that way. The issue is in the date formatting

quietone’s picture

Issue tags: +migrate-d7-d8

tagging

heddn’s picture

Version: 8.4.2 » 8.6.x-dev
Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

Can we reproduce this on 8.6 or 8.5? 8.4 is only getting critical bugs and security fixes at this point. Many folks have reported that d7 dates migrate just fine. We actually have automated tests that also say it works. Seems like a support request?

heddn’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

If this is reproducible at some point in the future, please re-open and add complete steps to reproduce.

Steve Tarnoski’s picture

I went through lots of trial and error before this solution (migrating from Drupal 7 to 8.6):

process:
  field_my_custom_d8_date:
    -
      plugin: extract
      source: field_my_custom_d7_date
      default: 0
      index:
        - 0
        - value
    -
      plugin: skip_on_empty
      method: process
    -
      plugin: format_date
      from_format: 'Y-m-d H:i:s'
      to_format: 'Y-m-d\TH:i:s'

In this case, we want the date field to remain empty if the source was also empty. We provide a default of 0, which allows this field to get skipped according to the next plugin.

GheorgheP’s picture

I changed the date format because the "DATE" field has the format that does not include H:i:s
Works for me:

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

TO

field_due_date:
    -
      plugin: sub_process
      source: field_due_date
      process:
        value:
          plugin: format_date
          from_format: 'Y-m-d H:i:s'
          to_format: 'Y-m-d'
          source: value
BrightBold’s picture

@GheorgheP's formatting change in #13 solved the problem for me. Thanks!

paulsheldrake’s picture

This config worked for me to get a D7 date field to go to D8 date field

field_article_online_pub_date:
    plugin: sub_process
    source: field_mises_published_date
    process:
      value:
        plugin: format_date
        from_format: 'Y-m-d H:i:s'
        to_format: 'Y-m-d\TH:i:s'
        source: value
juampynr’s picture

jkstermitz’s picture

Following my D7->D8 migration (via the migrate UI) the date field in the D8 db is populated with data in the format: 2017-11-19T00:00:00 but the value is not displayed in node view, nor in edit view modes (date field appears blank). The D7 originating date field is populated in the db in the format: 2017-11-19 00:00:00

Can anyone tell me what the date format is "supposed" to be in the D8 db? In my case, I've only populated Y M D, with no time in the original D7 version, and I'd like to preserve that in the final.

Can anyone tell me if there might e something else in the d8 setup preventing the date from displaying, even though the data is available in the db?

rajveergangwar’s picture

#2 worked for me.. Thanks

codeelegance’s picture

For anyone struggling with this AFTER a migration, this simple SQL query run in the database manager of your choice worked for me:

Field_dateline is the date field for my content type.

UPDATE node__field_dateline
SET 
    field_dateline_value = REPLACE(field_dateline_value,
        'T00:00:00',
        '')

UPDATE node_revision__field_dateline
SET 
    field_dateline_value = REPLACE(field_dateline_value,
        'T00:00:00',
        '')

The problem seems to be the additional 'T00:00:00' in the field. Now, to be honest, my date field does not contain time parts, so YMMV.

thhafner’s picture

#15 solved this issue for me.

ben.hamelin’s picture

Yep #15 for me too, specifically
to_format: 'Y-m-d\TH:i:s'

usmanjutt84’s picture

#15 works for me too.

rpayanm’s picture

It works for me, too:

  field_event:
    plugin: format_date
    from_format: 'Y-m-d H:i:s'
    to_format: 'Y-m-d'
    source: field_date/0/value