user2095165
user2095165

Reputation: 195

MySQL query value where current date

What is the proper way to query all data on current date? a function in mysql that will get the current date in 12:01 am and current date 11:59 pm

select * from tb_data where date between currentdate_starts and currentdate_ends

Upvotes: 2

Views: 3503

Answers (5)

Ukkin
Ukkin

Reputation: 91

Without using DATE(column) = CURDATE()

   SELECT * FROM tb_data WHERE date between concat(curdate(),' ','00:00:00') AND concat(curdate(),' ','23:59:59')

more info

Upvotes: 5

Surabhil Sergy
Surabhil Sergy

Reputation: 2006

Try using CURDATE()

SELECT field FROM table WHERE DATE(column) = CURDATE()


select * from tb_data where DATE(date) = CURDATE()

Documentation: CURDATE

Upvotes: 5

Tin Tran
Tin Tran

Reputation: 6202

well since there are so many answers. Try this one too and see if it's faster

SELECT * FROM tb_data WHERE date BETWEEN CURDATE() AND (CURDATE()+INTERVAL 1 DAY-INTERVAL 1 SECOND)

Upvotes: 2

Saharsh Shah
Saharsh Shah

Reputation: 29071

Use CURRENT_DATE() or CURDATE() function.

Try this:

SELECT * FROM tb_data WHERE DATE(dateCol) = CURRENT_DATE();

OR

SELECT * FROM tb_data WHERE DATE(dateCol) = CURDATE() 

Upvotes: 2

Nagaraj S
Nagaraj S

Reputation: 13484

CURDATE() returns the current date.

SELECT * from FROM tb_data WHERE DATE(column) = CURDATE()

Upvotes: 2

Related Questions