Mysql – How to choose a row with the current date time?

I tried to select only today’s records from the database table.

Currently I use

 SELECT * FROM `table` WHERE (`timestamp`> DATE_SUB(now(), INTERVAL 1 DAY));

But it needs the results of the past 24 hours, I need it to select only today’s results, ignore Time. How to select results based on date only?

Use DATE and CURDATE()

SELECT * FROM `table` WHERE DATE(`timestamp`) = CURDATE()

I want to use DATE and still use INDEX.

see the execution plan on the DEMO< /p>

I tried to select only today’s records from the database table.

Currently I use

SELECT * FROM `table` WHERE (`timestamp`> DATE_SUB(now(), INTERVAL 1 DAY));

But it needs the results of the past 24 hours, I need it to select only today’s Results, ignore time. How to select results based on date only?

Use DATE and CURDATE()

SELECT * FROM `table` WHERE DATE( `timestamp`) = CURDATE()

I want to use DATE and still use INDEX.

see the execution plan on the DEMO

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2935 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.