How PHP reads the last 1 hours of MySQL Records

Source: Internet
Author: User
The format of the time field is like this 2012-10-22 17:00:00

I want to read the last 1 hours of new records,$time_limit = 1 * 60 * 60;

Then query:

"SELECT * from Commentswhere TimeStamp > Now ()-$time _limit"

But there's no response, what's the problem?

Reply content:

The format of the time field is like this 2012-10-22 17:00:00

I want to read the last 1 hours of new records,$time_limit = 1 * 60 * 60;

Then query:

"SELECT * from Commentswhere TimeStamp > Now ()-$time _limit"

But there's no response, what's the problem?

You can do this by using the function on the field to get to the post index invalid

A different idea.

$timedate = Date (' y-m-d h:i:s ', Time ()), $hourtime = Date (' y-m-d h:i:s ', Time ()-3600); SELECT * from Comments  WHERE TimeStamp  between $timedate and  $timedate;

Timestamp why not build int, but use datetime type. In fact, upstairs can be one less condition, the current time does not need to make restrictions.

  • 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.