The date format for data records in MongoDB is
"DateCreated":isodate ("2011-12-20t07:22:50.836z")
After flipping through the MongoDB section of the PHP website, it's important to use the following key statements to manipulate the dates in MongoDB:
$start = new Mongodate (Strtotime ('-1 day '));
$end = new Mongodate (time ());
$resultObject =$db->user->find ("dateCreated" = = Array (' $gt ' = = $start, ' $lte ' + $end) ));
"NOTE: SELECT * from users WHERE age>33 and age<=40 similar $db->users->find (Array ("age" = = Array (' $gt ' = ', ' $lte ' = +)]); "
Example: This program implements the data that matches the conditions in MongoDB into the MySQL table.
<?php
$m = new Mongo ("localhost:27017");
$db = $m->database_name;
$start = new Mongodate (Strtotime ('-1 day '));
$end = new Mongodate (time ());
$count = $db->user->find (Array ("dateCreated" = = Array (' $gt ' = = $start, ' $lte ' = = $end)])->count ();
Echo $count;
$regobj = $db->user->find (Array ("dateCreated" = = Array (' $gt ' = = $start, ' $lte ' = = $end) ));
foreach ($regobj as $k 2)
{
$regemail = "'". $k 2["account"]. "'";
$regdate = $k 2["dateCreated"];
$regname = "'". $k 2["name"]. "'";
$id =mysql_connect (' localhost ', ' username ', ' passwd ');
mysql_select_db (' Sns_tongji ', $id);
$sql = "INSERT into Sns_new_register (account,name,date) VALUES ($regemail, $regname, Now ())";
mysql_query ("Set names UTF8");
if (mysql_query ($sql)) {
echo "Insert ok\n";
}
Else
{
Echo mysql_error (). " \ n ";
}
}
PHP Operation isodate Format date in MongoDB