I'm wondering how I can grab the date from a datepicker in a form (format is d/m/Y) and store it into my content entity. The form is produced from said content entity, so I don't see why there should be any issues between formats - but it doesn't copy directly. I know the date fields are stored as varchar(20) in the database, so it must be a string at some stage!
I'm grabbing the value from my form as below:
$dob = $form_state->get('field_dob'); $given = new DrupalDateTime($dob, \Drupal::currentUser()->getTimezone()); $given->setTimezone(new \DateTimeZone("UTC")); $dob = $given->format(DATETIME_DATETIME_STORAGE_FORMAT);
This gives me a string formatted as per the storage format, yet still won't copy across to the corresponding content entity.
Also, this is with Drupal 8.1.x. :)
Any insight would be much appreciated, thanks!