0

I inserted a DateTime in MongoDB,

how to reconstruct this object?

$mongo->insert(array('time' => new DateTime()));

Output when using find is:

[time] => Array
    (
        [date] => 2014-10-26 23:11:29.000000
        [timezone_type] => 3
        [timezone] => Europe/Berlin
    )

I know I can use

DateTime::createFromFormat(...);

But is there a more convenient way?

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • You can use native serialization `$mongo->insert(array('time' => serialize(new DateTime())));` `var_dump(unserialize($array['time']));` Not sure this is more convenient though – Steve Oct 26 '14 at 22:31
  • You're using the wrong object for datetime in mongodb. see the duplicate closed against. – hakre Oct 26 '14 at 23:24

0 Answers0