Mapping date field's "from" and "to" values during migration with Migrate

Public

In your migration class you need to implement prepareRow() function:

Get raw version
php
  1. /**
  2.  * Implementation of Migration::prepareRow().
  3.  * @param $row
  4.  */
  5. public function prepareRow($row) {
  6. if (parent::prepareRow($row) === FALSE) {
  7. return FALSE;
  8. }
  9.  
  10. // Handle date field.
  11. $date_data = array(
  12. 'from' => $row->old_date_from_value,
  13. 'to' => $row->old_date_to_value,
  14. );
  15.  
  16. // Datetime field handler accepts data as json array.
  17. $row->old_date = drupal_json_encode($date_data);
  18. return TRUE;
  19. }

Then in your migration class constructor you map your date field like this:

Get raw version
php
  1. $this->addFieldMapping('field_date', 'old_date');