Default value to 'datetime' field in form loaded from the database I want to display the datetime field on my Drupal 8 form with some date loaded from the database, but the front end always shows empty fields as if no data has been provided. I tried several combinations to default_value field, but none of them are showing any thing. 

The code I am using is the following.

$form['dateopening'] = array(
  '#type' =&gt; 'datetime',
  '#title' =&gt; t('Opening Date'),
  '#default_value'=&gt; date('Y-m-d H:i:s', strtotime($dateFromDB)),
);


Why doesn't it set the default value as expected?
The response is in this thread : on stackoverflow

$form['valid_dt'] = array(
    '#type' =&gt; 'datetime',
    '#default_value' =&gt; DrupalDateTime::createFromTimestamp($data-&gt;valid_dt),
    '#title' =&gt; $this-&gt;t('Valid'),      
);