Possible Duplicate:
Mysql query: retrieve current date query
I need a MySQL query that will select some data that contains todays date. I have built the following query:
SELECT CRM_TRATATIVAS.ID_Vendedor, CRM_TRATATIVAS.Fecha
FROM CRM_TRATATIVAS
GROUP BY CRM_TRATATIVAS.ID_Vendedor, CRM_TRATATIVAS.Fecha, CRM_TRATATIVAS.ID_Categoria
HAVING (((CRM_TRATATIVAS.ID_Vendedor)=10 Or (CRM_TRATATIVAS.ID_Vendedor)=29 Or (CRM_TRATATIVAS.ID_Vendedor)=32) AND ((CRM_TRATATIVAS.Fecha)=Date()) AND ((CRM_TRATATIVAS.ID_Categoria)=14));
If I take the =Date() away, it works. Any ideas what the problem could be?
The final data show be something like this without the brackets and dots (I couldn’t find how to make a table!
Fecha Vendedor
2012-12-03 10:12:13 (10)
2012-12-03 12:14:16 (10)
2012-12-03 09:15:46 (29)
2012-12-03 13:35:56 (32)
Fixed!
I fixed by using this query.
SELECT CRM_TRATATIVAS.ID_Vendedor, CRM_TRATATIVAS.Fecha
FROM CRM_TRATATIVASGROUP BY CRM_TRATATIVAS.ID_Vendedor, CRM_TRATATIVAS.Fecha, CRM_TRATATIVAS.ID_Categoria
HAVING (((CRM_TRATATIVAS.ID_Vendedor)=10 Or (CRM_TRATATIVAS.ID_Vendedor)=29 Or (CRM_TRATATIVAS.ID_Vendedor)=32) AND ((DATE(CRM_TRATATIVAS.Fecha)) = CURDATE()) AND ((CRM_TRATATIVAS.ID_Categoria)=14));
As Fecha was a DATETIME column, I added Date just before the reference to convert it into a date.
Try to change:
with this:
CURDATE()returns the current date, andDATE(Fecha)returns just the date part ofFecha(without hours, minutes and seconds). I also suggest you to write the query this way, that looks cleaner: