I am trying to copy the value of a Date/Time Webform element to a Date/Time field set on the article node.
Below is the source code of the Date/Time Webform element:
expiry_date:
'#type': datetime
'#title': 'Expiry Date'
'#title_display': before
'#required': true
'#required_error': 'You must add an expiry date'
'#date_date_format': ''
'#date_year_range': '2019:2100'
'#date_time_format': ''
Below is my custom handler:
// Get an array of the values from the submission.
$values = $webform_submission->getData();
// Get 'Expiry Date' Value.
$ExpiryDate = $values['expiry_date'];
date_default_timezone_set('UTC'); // Sett the time to 'UTC' time zone.
// Format the "Expiry Date" to return "Y-m-d\TH:i:s".
//$FormattedExpiry = date('Y-m-d\TH:i:s', $ExpiryDate);
// Create a new "Article" node.
$article = \Drupal\node\Entity\Node::create([
'type' => 'article',
// Set the node field values.
'title' => $Title,
'langcode' => 'en',
'uid' => $CurrentUid,
'status' => '1',
'created' => $current_time,
'field_expiry_date' => $ExpiryDate, // $FormattedExpiry,
]);
// Save the created node.
$article->save()
But I am facing the below error:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_expiry_date_value' at row 1: INSERT INTO {node__field_expiry_date} (entity_id, revision_id, bundle, delta, langcode, field_expiry_date_value) VALUES (
:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5);
Array (
[:db_insert_placeholder_0] => 84
[:db_insert_placeholder_1] => 88
[:db_insert_placeholder_2] => article
[:db_insert_placeholder_3] => 0
[:db_insert_placeholder_4] => en
[:db_insert_placeholder_5] => 2021-05-25 11:26:02 +03:00
)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToDedicatedTables() (line 1414 of /home/username/public_html/example.com/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).