MySQL Date comparison

Source: Internet
Author: User

The interface used to make a date comparison, to return a period of time the data list.

The Data table field is "End_time", the time format is 2014-05-30 13:12:10, want to check the deadline for registration data.

Select field name from table where end_time > Current time;

The MySQL data table holds the Time field format Date,datetime,time,timestamp, and the comparison operator is consistent on both sides of the data format.

If we look at the number of news for 2014-05-30,

SELECT count (id) from tb_news WHERE end_time >= ' 2014-05-30 00:00:00 ' and Add_time <= ' 2014-05-30 23:59:59 '

The results obtained from this >= are expected, and the results obtained by <= are not what we want.

' 2014-05-30 ' is equivalent to ' 2014-05-30 00:00:00 ', and the record less than May 30 should be until May 29 23:59:59

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.