MySQL How to SELECT data from table which recorded today?

前端 未结 8 1761
死守一世寂寞
死守一世寂寞 2021-02-04 04:35

Use PHP and MySQL. In my table, there is date field (datetime) recorded by NOW() sql function. Example value of data in this field is 2010-10-07 10:57:36. Ho

8条回答
  •  清酒与你
    2021-02-04 05:12

    Try this:

    SELECT * FROM table WHERE date > CURDATE();
    

    CURDATE() will return the current date as 2011-10-07 which will be cast to 2011-10-07 00:00:00 when comparing datetimes to it.

    Note that if you use DATE(date) = CURDATE() you will run a date conversion for every row in the table, which will be really bad for your perfomance if you have many rows and/or you need to run the query often. Also make sure you have an index on date, otherwise both methods will be even slower.

提交回复
热议问题