note 108970 modified in class.datetime by googleguy

From: Date: Sun, 31 Jul 2016 14:33:20 +0000
Subject: note 108970 modified in class.datetime by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206140@lists.php.net to get a copy of this message
DateInterval does not support split seconds (microseconds or milliseconds etc.) when doing a diff between two DateTime objects that contain microseconds. So you cannot do the following, for example: <?php $d1=new DateTime("2012-07-08 11:14:15.638276"); $d2=new DateTime("2012-07-08 11:14:15.889342"); $diff=$d2->diff($d1); print_r( $diff ) ; /* returns: DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) */ ?> You get back 0 when you actually want to get 0.251066 seconds. --was-- DateTime does not support split seconds (microseconds or milliseconds etc.) I don't know why this isn't documented. The class constructor will accept them without complaint, but they are discarded. There does not appear to be a way to take a string like "2012-07-08 11:14:15.638276" and store it in an objective form in a complete way. So you cannot do date math on two strings such as: <?php $d1=new DateTime("2012-07-08 11:14:15.638276"); $d2=new DateTime("2012-07-08 11:14:15.889342"); $diff=$d2->diff($d1); print_r( $diff ) ; /* returns: DateInterval Object ( [y] => 0 [m] => 0 [d] => 0 [h] => 0 [i] => 0 [s] => 0 [invert] => 0 [days] => 0 ) */ ?> You get back 0 when you actually want to get 0.251066 seconds. http://php.net/manual/en/class.datetime.php

« previous php.notes (#206140) next »