note 113297 added to mongodate.construct
| From: | gb at tekkie dot ro | Date: | Sun, 22 Sep 2013 15:12:58 +0000 |
| Subject: | note 113297 added to mongodate.construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196348@lists.php.net to get a copy of this message | ||
Please note that the second parameter should be a microseconds value, not a miliseconds one, as
stated in the documentation.
I am using the code below to show you what I mean:
<?php
$example = new \DateTime('2013-09-22T10:41:44.451999');
$seconds = $example->getTimestamp();
// this is what documentation misleads you to think is needed
$miliseconds = floor($example->format('u') / 1000);
// this is what you should really use
$microseconds = $example->format('u');
$fullToString = $example->format('Y-m-d\TH:i:s.uP');
$collection->insert(array(
'timeMicroseconds' => new \MongoDate($seconds, $microseconds),
'toString' => $fullToString,
));
$collection->insert(array(
'timeMiliseconds' => new \MongoDate($seconds, $miliseconds),
'toString' => $fullToString,
));
?>
Let's take a look in the database to see what is really stored:
{
"_id" : ObjectId("523f07cfc2b581eb7f069b1d"),
"timeMicroseconds" : ISODate("2013-09-22T07:41:44.451Z"),
"toString" : "2013-09-22T10:41:44.451999+03:00"
}
{
"_id" : ObjectId("523f07cfc2b581eb7f069b1e"),
"timeMiliseconds" : ISODate("2013-09-22T07:41:44.000Z"),
"toString" : "2013-09-22T10:41:44.451999+03:00"
}
----
Server IP: 69.147.83.199
Probable Submitter: 82.208.146.104
----
Manual Page -- http://php.net/manual/en/mongodate.construct.php
Edit -- https://master.php.net/note/edit/113297
Del: integrated -- https://master.php.net/note/delete/113297/integrated
Del: useless -- https://master.php.net/note/delete/113297/useless
Del: bad code -- https://master.php.net/note/delete/113297/bad+code
Del: spam -- https://master.php.net/note/delete/113297/spam
Del: non-english -- https://master.php.net/note/delete/113297/non-english
Del: in docs -- https://master.php.net/note/delete/113297/in+docs
Del: other reasons-- https://master.php.net/note/delete/113297
Reject -- https://master.php.net/note/reject/113297
Search -- https://master.php.net/manage/user-notes.php