Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do i pull only the records for todays date no other day query
my query is below but its pulling records from previous day and if u can how can i also accend the data by the time

SQL
SELECT name, date, time, queue FROM sms_traffic_db.table_data WHERE date <= adddate(NOW(), INTERVAL +1 day);
Posted
Updated 17-Oct-13 5:20am
v2

Now() + 1 Day = [Yesterday, Tomorrow] (but tomorrow doesn't exist yet, so...)

Have a look to:
https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html[^]

Have you tried the CURDATE (Current date = today)´

Or you get the NOW and then use the DATE to extract the current day for your query.

Working query copied from OP's Comment below to be easier to spot
SQL
$query = "SELECT name, date, time, queue FROM sms_traffic_db.table_data WHERE date = CURDATE()";
 
Share this answer
 
v3
Comments
Nico_Travassos 17-Oct-13 11:33am    
i have tried CURDATE(Current date = today) and NOW and Date does not work
Nelek 17-Oct-13 11:40am    
Did you try to debug when using them? Logic says they should work, you say they don't... How are you using them? Which value is actually being used in the query? How is the date format of the DB you are querying?

Please use the "improve question" widget and give a bit info about the tests you did. Maybe someone else can spot your error in the new code.
Nico_Travassos 17-Oct-13 11:38am    
$query = "SELECT name, date, time, queue FROM sms_traffic_db.table_data WHERE date = CURDATE()";

Okay sorted it out CURDATE works i used it wrong

Thank you
Nelek 17-Oct-13 11:41am    
Nice :), you are welcome. Ignore my previous (above) comment then, you were faster than me :)
Try this:

SELECT name, date, time, queue FROM sms_traffic_db.table_data WHERE date = GetDate()
 
Share this answer
 
Comments
Nico_Travassos 17-Oct-13 11:31am    
Does not work. it clears my table.
Richard C Bishop 17-Oct-13 11:36am    
Well, the query does not clear your table. Maybe something else you have is doing that, but definitely not the query.
Nico_Travassos 17-Oct-13 11:38am    
$query = "SELECT name, date, time, queue FROM sms_traffic_db.table_data WHERE date = CURDATE()";

Okay sorted it out CURDATE works i used it wrong
Richard C Bishop 17-Oct-13 11:42am    
Good work!

P.S. It was my mistake for not seeing your MySQL tag.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900