I want to insert a date into a collection.
I use the class MongoDate
to create the date object:
$today = new MongoDate(strtotime(date(\'Y-m-d 00
Remove old document and insert
$bill = array(
"_id" => 1,
"name" => "A",
"lastModified" => new MongoDate()
);
$collection->insert($bill);
$dt = new DateTime(date('Y-m-d'), new DateTimeZone('UTC'));
$ts = $dt->getTimestamp();
$today = new MongoDate($ts);
This is working.
FYI: If you need date created for your object model.
$date_created = new \MongoDB\BSON\UTCDateTime(time()*1000);
That works in the new php version of mongodb:
new MongoDB\BSON\UTCDateTime((new DateTime($today))->getTimestamp()*1000)