Skip to content

Instantly share code, notes, and snippets.

@vchabot
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vchabot/b05cec633f855e88f7ad to your computer and use it in GitHub Desktop.
Save vchabot/b05cec633f855e88f7ad to your computer and use it in GitHub Desktop.
Tips for \DateTime::createFromFormat method (with missing format params)
<?php
// @see http://php.net/manual/fr/datetime.createfromformat.php
$date = \DateTime::createFromFormat('Ymd', '20140501');
var_dump($date->format('Y-m-d H:i:s')); // string(19) "2014-05-01 16:09:40" (system time)
$date = \DateTime::createFromFormat('!Ymd', '20140501');
var_dump($date->format('Y-m-d H:i:s')); // string(19) "2014-05-01 00:00:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment