Convert a date with format (2017-05-27) to save in node created field I've been looking around for a little while for what I thought would be a simple question to answer but I cannot seem to find the answer.

The question is: How can I convert a date with the format 2017-05-27 into a Drupal safe format for saving into the database?

I have looked inside Drupal\datetime\DateTimeComputed but I'm not sure that is the right place. Any help would be appreciated.
The node created field is a Timestamp Field. Use the php function strtotime() to convert the string to a Unix timestamp:

$timestamp = strtotime('2017-05-27');


and store the value in the created field:

$node-&gt;created-&gt;value = $timestamp;


You can also use the method setCreatedTime():

$node-&gt;setCreatedTime($timestamp);