{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/118","repository_url":"https://api.github.com/repos/mongodb/mongo-php-library","labels_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/118/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/118/comments","events_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/118/events","html_url":"https://github.com/mongodb/mongo-php-library/issues/118","id":132650947,"number":118,"title":"MongoDB\\BSON\\Date unable to assign date in desired format","user":{"login":"hoodlumer","id":13599950,"avatar_url":"https://avatars.githubusercontent.com/u/13599950?v=3","gravatar_id":"","url":"https://api.github.com/users/hoodlumer","html_url":"https://github.com/hoodlumer","followers_url":"https://api.github.com/users/hoodlumer/followers","following_url":"https://api.github.com/users/hoodlumer/following{/other_user}","gists_url":"https://api.github.com/users/hoodlumer/gists{/gist_id}","starred_url":"https://api.github.com/users/hoodlumer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hoodlumer/subscriptions","organizations_url":"https://api.github.com/users/hoodlumer/orgs","repos_url":"https://api.github.com/users/hoodlumer/repos","events_url":"https://api.github.com/users/hoodlumer/events{/privacy}","received_events_url":"https://api.github.com/users/hoodlumer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-10T09:48:12Z","updated_at":"2016-02-10T22:23:13Z","closed_at":"2016-02-10T21:42:12Z","body":"Objective is to assign a mongodb ISODate to a php variable. So this is a BSON date object and I am trying to get the date or rather milliseconds property, which I am unable to get. \r\n\r\n```\r\nMongoDB\\BSON\\UTCDateTime Object ( [milliseconds] => 1455454800000 )\r\n```\r\n\r\nPHP MongoDB Environment:\r\nmongodb version  1.1.0\r\nmongodb stability  stable\r\nibmongoc version  1.1.2\r\nlibbson version  1.1.3\r\n\r\nMongoDB Pecl Driver php_mongodb-1.1.0-5.6-nts-vc11-x86 \r\nmongodb/mongo-php-library 1.0.0\r\n(composer gave exception php_mongodb driver not installed when using the php_mongodb-1.1.0-5.6-nts-vc11-x64 but accepted the php_mongodb-1.1.0-5.6-nts-vc11-x86 ) \r\n\r\n2016-02-09T22:12:26.428+0000 I CONTROL  [initandlisten] db version v3.2.1\r\n2016-02-09T22:12:26.428+0000 I CONTROL  [initandlisten] git version: a14d55980c2\r\ncdc565d4704a7e3ad37e4e535c1b2\r\n2016-02-09T22:12:26.429+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL\r\n 1.0.1p-fips 9 Jul 2015\r\n2016-02-09T22:12:26.429+0000 I CONTROL  [initandlisten] allocator: tcmalloc\r\n2016-02-09T22:12:26.429+0000 I CONTROL  [initandlisten] modules: none\r\n2016-02-09T22:12:26.429+0000 I CONTROL  [initandlisten] build environment:\r\n2016-02-09T22:12:26.430+0000 I CONTROL  [initandlisten]     distmod: 2008plus-ssl\r\n2016-02-09T22:12:26.430+0000 I CONTROL  [initandlisten]     distarch: x86_64\r\n2016-02-09T22:12:26.430+0000 I CONTROL  [initandlisten]     target_arch: x86_64\r\n\r\n\r\ndocument:\r\n```\r\n{\r\n        \"_id\" : ObjectId(\"56b91366bb782f1d925ef9df\"),\r\n        \"playerLastName\" : \"Smith\",\r\n        \"fixture\" : [\r\n                {\r\n                        \"opposition\" : \"Bisons\",\r\n                        \"date\" : ISODate(\"2016-02-14T13:00:00Z\"),\r\n                        \"venue\" : \"Parklands\",\r\n                        \"available\" : 0\r\n                }\r\n        ],\r\n        \"playerFirstName\" : \"John\"\r\n} \r\n```\r\nphp\r\n```\r\nforeach ($document as $value) {\r\n\t$fixtureSel_firstName = $value[\"playerFirstName\"];\r\n\t$fixtureSel_lastName = $value[\"playerLastName\"];\r\n\tfor($i = 0; $i < count($value['fixture']); $i++) {\r\n\t\t$fixtureSel_opposition = $value['fixture'][$i]['opposition'];\r\n\t\t$fixtureSel_date = $value['fixture'][$i]['date'];\r\n\t\t\r\n\t\t$utcdatetime = new MongoDB\\BSON\\UTCDateTime($fixtureSel_date);\r\n\t\t$datetime = $utcdatetime->toDateTime();\r\n\t\tvar_dump($datetime);\r\n```\r\n\r\nError\r\nPHP Fatal error:  Uncaught exception 'MongoDB\\Driver\\Exception\\InvalidArgumentException' with message 'MongoDB\\BSON\\UTCDateTime::__construct() expects parameter 1 to be long, object given'\r\n\r\nObviously you can't use the Date object returned, but how do you get the milliseconds and pass that ? \r\n\r\nIf I pass a string\r\n```\r\n$date = '1455454800000';\r\n\r\n$utcdatetime = new MongoDB\\BSON\\UTCDateTime($date);\r\n$datetime = $utcdatetime->toDateTime();\r\n$mydate = $datetime->format('Y-m-d H:i:s');\r\nprint $mydate;\r\n```\r\nI get 2016-02-14 13:00:00 which is what I am looking for.\r\n\r\nAppreciate any pointers on this."},"comment":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/comments/182605435","html_url":"https://github.com/mongodb/mongo-php-library/issues/118#issuecomment-182605435","issue_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/118","id":182605435,"user":{"login":"jacqueswaller","id":3794488,"avatar_url":"https://avatars.githubusercontent.com/u/3794488?v=3","gravatar_id":"","url":"https://api.github.com/users/jacqueswaller","html_url":"https://github.com/jacqueswaller","followers_url":"https://api.github.com/users/jacqueswaller/followers","following_url":"https://api.github.com/users/jacqueswaller/following{/other_user}","gists_url":"https://api.github.com/users/jacqueswaller/gists{/gist_id}","starred_url":"https://api.github.com/users/jacqueswaller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacqueswaller/subscriptions","organizations_url":"https://api.github.com/users/jacqueswaller/orgs","repos_url":"https://api.github.com/users/jacqueswaller/repos","events_url":"https://api.github.com/users/jacqueswaller/events{/privacy}","received_events_url":"https://api.github.com/users/jacqueswaller/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T22:23:13Z","updated_at":"2016-02-10T22:23:13Z","body":"ah, yeah you're right in the x86 version of the driver I believe it's meant to take a string for the constructor since there's otherwise no way to supply a giant number like 1455454800000."}}