Pipe and exclamation mark characters reset all fields (year, month, day, hour, minute, second, fraction, and timezone information) to the Unix Epoch.

$date = '2015-10-21';

$date_1 = DateTime::createFromFormat('Y-m-d', $date);

// Y-m-d| will set the year, month and day to the information found
// in the string to parse, and sets the hour, minute and second to 0.
$date_2 = DateTime::createFromFormat('Y-m-d|', $date);

var_dump($date_1->format('r'), $date_2->format('r'));
// string(31) "Wed, 21 Oct 2015 04:32:09 +0200"
// string(31) "Wed, 21 Oct 2015 00:00:00 +0200"

Found a typo? Something wrong with this content?

Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all contributors.