In my case, I was getting this error because I used microtime(true) as input:
$now = DateTime::createFromFormat('U.u', microtime(true));
In those moments when microtime returns a float with zeros as decimals, this error appeared.
So, I had to check if its decimal numbers and add the decimal part:
$aux = microtime(true); $decimais = $aux - floor($aux); if($decimais<=10e-5) $aux += 0.1; $now = DateTime::createFromFormat('U.u', $aux);
EDIT
Due to floating point accuracy, sometimes the floor brings the floor of a madman, so I had to use a more direct approach:
$aux = microtime(true); $now = DateTime::createFromFormat('U.u', $aux); if (is_bool($now)) $now = DateTime::createFromFormat('U.u', $aux += 0.001);
carla
source share