tags:

views:

235

answers:

2

I have a query for getting today's records from table. I have inserted the date field by using now().

select u.*,p.* from user_brands as u inner join products as p where u.parent_id = p.cat_id and date_format( p.date, '%Y-%m-%d' ) = curdate( )

By using this query every first time I am getting empty results, once if I refresh the page I am getting the results. Why is it not returning values for the first time?

A: 

try with this query:

select u.*,p.* from user_brands as u inner join products as p where u.parent_id = p.cat_id and YEAR(p.date) = YEAR(now()) and MONTH(p.date) = MONTH(now()) and DAY(p.date) = DAY(now())
mck89
Thanks. Your code is working fine. But my doubt is why i am getting the empty result set first time when im using date_format = curdate()
paulrajj
+1  A: 

A simpler version is to use condition DATE(p.date) = CURDATE(). As for the empty first set, no idea. You mention that you refresh a page, does your query work in mysql command line or other non-web browser interface?

kari