The MongoDate classes in the mongo driver have no special support for comparison operators. The behavior you're seeing is likely internal PHP behavior, where comparing two objects with <
, <=
, >
, and >=
operators examines the properties in order. It just so happens that MongoDate declares its $sec
property before $usec
, so this works out. I didn't find this behavior documented in the PHP manual, but it is discussed in this comment on the page where I'd expect to find it.
You may want to track PHP-226, as there are plans to add a helper method to return the float value of a MongoDate (akin to microtime(true)
). As-is, the __toString()
return value isn't very helpful, since microseconds appear before seconds.
I've also opened PHP-979 to track this as a feature request (overloading support for comparison operators).