Need help for DATE_FORMAT (p.date, '% Y-% m-% d') = CURDATE ()

I have a query to get today's records from a table. I have inserted a date field 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( )

      

Using this query every time I get empty results, once, if I refresh the page, I get results. Why doesn't this return values ​​the first time?

+2


source to share


2 answers


A simpler version is to use a condition DATE(p.date) = CURDATE()

. As for the empty first set, I don't know. You mark that you are refreshing the page, is your query doing the job on the mysql command line, or in another non-web browser?



+1


source


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())

      

0


source







All Articles