I have a json file full of data exported from a wordpress site, one field being a string representing a date and time: "03/15/2012 14:46:19". I would like to import that string into a date and time field of a drupal 8 content type.

I am using a Migration from Source YML file.

  name: date
  label: 'Date'
  selector: date

Then in process:

  field_press_release_date: date        # is it as easy as this?

Is there a special plug in I'm not seeing listed on: https://www.drupal.org/docs/8/api/migrate-api/migrate-process-plugins

I see format date, but couldn't get any format to work. I have complete control over the format of the date string, I have to do some processing of data from wordpress before drupal so I can do pretty much whatever is needed, if it really is as easy as setting the date_field to the date_string from the fields list, what format does date_string need to be in?

I cannot find a simple example of importing a string into a date and time field, thank you for any assistance!

1 Answer 1


The migrate plugin that handles this is FormatDate. It looks like you are missing the input and output date formats. For date-only, you would do something like

    plugin: format_date
    from_format: 'm/d/Y'
    to_format: 'Y-m-d'
    source: event_date

and for date+time, it would look something like

    plugin: format_date
    from_format: 'm/d/Y H:i:s'
    to_format: 'Y-m-d\TH:i:s'
    source: event_time

When migrating into the core datetime/daterange fields, the to_format needs to be those strings (these were written to be generic, not just for those field types). The from_format gets adjusted to your input source. If you look at the references below, there is also a way to specify time zone.

That plugin is unit tested, so core doesn't provide any YAML example, but you may be able to glean samples from FormatDateTest.


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.