Search code examples
phpmongodbphp-7mongodate

Create Date Object MongoDB new php driver


I'm trying to create Date Object to create a document in MongoDB with PHP.

I saw in PHP documentation new MongoDate() but I'm using the 'new' drivers MongoDB for PHP7 (this doc) and I can't use this.

I tried with MongoDB\BSON\Date but I got Class 'Date' not found

I searched across the new driver documentation & stackoverflow but nothing ...

Does anyone know how to create Date Object with the 'new' php driver ?


Solution

  • The name of the class is \MongoDB\BSON\UTCDateTime: http://php.net/manual/en/class.mongodb-bson-utcdatetime.php