Skip to main content
2 of 2
added 496 characters in body
berramou
  • 7.3k
  • 2
  • 13
  • 31

The expiry_date from webform return something like 2021-05-25 11:26:02 +03:00 so you should to format it before you passe it to create like the following:

// Get 'Expiry Date' Value.
$ExpiryDate = $values['expiry_date'];
// Format the "Expiry Date" to return "Y-m-d\TH:i:s".
// Here use strtotime to format date correctly 
$FormattedExpiry = date('Y-m-d\TH:i:s', strtotime($ExpiryDate));

Then passe $FormattedExpiry instead of $ExpiryDate:

$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' => $FormattedExpiry,
    ]);

Update: your date already has +3h, if you want to not add 3 hours to your time there is two options i guess:

  1. Change you webform field settings to work with UTC to get the value of $values['expiry_date'] something like 2021-05-25 11:26:02 without +03:00

  2. Remove the +03:00 before date conversion from $values['expiry_date'] by change the line $ExpiryDate = $values['expiry_date']; with something like:

    $ExpiryDate = explode('+', $values['expiry_date'])[0];

berramou
  • 7.3k
  • 2
  • 13
  • 31