Poddy Posted June 28, 2008 Share Posted June 28, 2008 i have this code: $sql = "select * from `data` where `name` LIKE '$name' AND `spot` LIKE '$line' AND `piret` LIKE '$piret' AND `timestamp` BETWEEN '$before' AND '$after' ORDER BY `timestamp` DESC "; it works fine, the problem is if i select from dates like 2008-06-11 to 2008-06-25 i get all dates between them, but those with 25 i do not get.. is there any way to get around this? thanks Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 I would personally use >= <= rather than between, so something like: $sql = "select * from `data` where `name` LIKE '$name' AND `spot` LIKE '$line' AND `piret` LIKE '$piret' AND `timestamp` >= '$before' AND `timestamp` <= '$after' ORDER BY `timestamp` DESC "; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2008 Share Posted June 28, 2008 BETWEEN is inclusive. If it is not working for you, something is wrong with your values. Show us what echoing $sql looks like with values and show some of your data in your database. Quote Link to comment Share on other sites More sharing options...
Poddy Posted June 28, 2008 Author Share Posted June 28, 2008 thanks for the reply but it still dosent display the last day query: select * from `data` WHERE `timestamp` >= '2008-06-15' AND `timestamp` <= '2008-06-25' ORDER BY `timestamp` DESC result: Edit Delete 101 4 fghf 456 fghfg 1 2008-06-24 17:09:10 5 5 5 Edit Delete 96 5 sdfds 324 dfgdf 1 2008-06-15 17:08:12 5 5 5 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2008 Share Posted June 28, 2008 Your timestamp column is a DATETIME data type. Use the mysql DATE() function around it so that only the DATE portion will be used in the comparisons. Quote Link to comment Share on other sites More sharing options...
Poddy Posted June 28, 2008 Author Share Posted June 28, 2008 Solved, changed the column to DATE type and added insertion of date in the insert query, which i tried to avoid.. works well now thanks everyone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.