Render array value empty for Datetime field I'm using hook_form_alter to modify an admin edit node screen. The form has a datetime field which I'm unable to get the value for in the render array. textfields value usually appears in value->#default_value.

xxx_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  print(json_encode($form['field_date_test']['widget']));
}




When the page loads, the value is in the input field but I can't find where I can get hold of the value before the page loads.
The solution was $item['value']['#default_value']-&gt;render(). This outputs the value in the following format Y-m-d H:i:s e.

Alternatively, calling format('Y-m-d') or any other format string will update accordingly

because '#default_value' was of type DrupalDateTime which must not implement jsonSerialize this is why I was getting and empty object for a value when dumping out as JSON.