Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference with microseconds precision between two DateTime in PHP

Tags:

I can get a datetime with microseconds in PHP with a workaround as:

list($usec, $sec) = explode(" ", microtime());
echo date("Y-m-d\TH:i:s", $sec) . "." . floatval($usec)*pow(10,6);

I need the difference with microseconds between two datetimes, can't get a workaround for:

$datetime1 = new DateTime('2013-08-14 18:49:58.606');
$datetime2 = new DateTime('2013-08-14 22:27:19.272');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%h hours %i minutes %s seconds %u microseconds');

DateInterval::format doesn't has the format character %u or equivalent for microseconds.

Anyone knows a workaround for this?