PHP Operation isodate Format date in MongoDB

Source: Internet
Author: User
Tags php website

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.