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?
DateInterval
does not support microseconds. And alsoDateTime
does not support them. All points that you have to do all related calculations manually to achieve such precision. – Emitteru
format fairly recently (PHP 5.5?), though I can't find any evidence that it's supported by DAteInterval – KytheraF
andf
for microseconds (with and without leading zeroes respectively) toDateInterval::format
. – Krystynakshatriya