By editor, 4 December, 2015 Question How to create and format a date field. It is same as normal node creation but must be in format "Y-m-d" (YYYY-MM-DD) Example: $dateTime = \DateTime::createFromFormat('Y-m-d','2000-01-30'); $newDateString = $dateTime->format('Y-m-d\TH:i:s'); $node = \Drupal\node\Entity\Node::create(array( 'type' => 'article', 'title' => 'The title', 'langcode' => 'en', 'uid' => 1, 'status' => 1, 'body' => array('The body text'), //'field_date' => array("2000-01-30"), 'field_date' => $newDateString, )); $node->save(); Tags Drupal 8 Code Node Add new comment Create a node programmatically in Drupal 8 Comments4 You must have JavaScript enabled to use this form. Your name Subject Comment About text formats Text format Plain textBasic_html Plain text No HTML tags allowed. Lines and paragraphs break automatically. Web page addresses and email addresses turn into links automatically. I tried 'field_date' =>… I tried 'field_date' => array("2000-01-30"), for drupal 8.1.8 but seem it's not working. Reply Node with date field DATETIME_DATETIME_STORAGE_FORMAT, which is 'Y-m-d\TH:i:s' $dateTime = \DateTime::createFromFormat('Y-m-d','2000-01-30'); $newDateString = $dateTime->format('Y-m-d\TH:i:s'); and 'field_date' => $newDateString, https://www.drupal.org/node/2795353 Reply Thankyou !!! Thankyou !!! Reply Thx Thx Reply
I tried 'field_date' =>… I tried 'field_date' => array("2000-01-30"), for drupal 8.1.8 but seem it's not working. Reply
Node with date field DATETIME_DATETIME_STORAGE_FORMAT, which is 'Y-m-d\TH:i:s' $dateTime = \DateTime::createFromFormat('Y-m-d','2000-01-30'); $newDateString = $dateTime->format('Y-m-d\TH:i:s'); and 'field_date' => $newDateString, https://www.drupal.org/node/2795353 Reply
Comments4
I tried 'field_date' =>…
I tried 'field_date' => array("2000-01-30"), for drupal 8.1.8 but seem it's not working.
Node with date field
DATETIME_DATETIME_STORAGE_FORMAT, which is 'Y-m-d\TH:i:s'
$dateTime = \DateTime::createFromFormat('Y-m-d','2000-01-30');
$newDateString = $dateTime->format('Y-m-d\TH:i:s');
and
'field_date' => $newDateString,
https://www.drupal.org/node/2795353
Thankyou !!!
Thankyou !!!
Thx
Thx