Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I am trying to select only today's records from a database table.

Currently, I use

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

But this takes results for the last 24 hours, and I need it to only select results from today, ignoring the time. How can I select results based on the date only?

1 Answer

0 votes
by (40.7k points)

You can try using DATE and CURDATE() like this:

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

Note: DATE uses INDEX.

have a look at the execution plan on the DEMO

Related questions

0 votes
3 answers
asked Dec 29, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...