How to get formatted date string from a DateTimeItem object I have a standard Drupal date field 'My date' (field_my_date). I can get its value:

$node-&gt;field_my_date-&gt;value  // returns: "2017-12-14T08:00:00"


But I want to get a formatted date string, which should look like: "14.12.2017".

If I analyse the field in the interactive shell (drush core-cli), then I see, that I can get the DateTimeFieldItemList object or DateTimeItem object:

&gt;&gt;&gt; $node-&gt;field_my_date
=&gt; Drupal\datetime\Plugin\Field\FieldType\DateTimeFieldItemList {#8836
 0: Drupal\datetime\Plugin\Field\FieldType\DateTimeItem {#8841},
}

&gt;&gt;&gt; $node-&gt;field_my_date[0]
=&gt; Drupal\datetime\Plugin\Field\FieldType\DateTimeItem {#8841
 value: [
   "value" =&gt; "2017-12-14T08:00:00",
 ],
}


But I have not found any method to reformat the date string. Is there some possibility to define the format of the output date string? Or do I have to reformat the output string e.g. like this:

date("j.n.Y", strtotime($node-&gt;field_my_date-&gt;value));
A date field has two properties, value to store the date in UTC and date, a computed field returning a DrupalDateTime object, on which you can use the methods getTimestamp() or format():

// get unix timestamp
$timestamp = $node-&gt;field_date-&gt;date-&gt;getTimestamp();
// get a formatted date
$date_formatted = $node-&gt;field_date-&gt;date-&gt;format('Y-m-d H:i:s');


For a date range field:

// formatted start date
$start_date_formatted = $node-&gt;field_date-&gt;start_date-&gt;format('Y-m-d H:i:s');
// formatted end date
$end_date_formatted = $node-&gt;field_date-&gt;end_date-&gt;format('Y-m-d H:i:s');