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 Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/ 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 "; Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/#findComment-576666 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. Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/#findComment-576704 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 Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/#findComment-576708 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. Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/#findComment-576715 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 Link to comment https://forums.phpfreaks.com/topic/112314-solved-making-a-selection-of-between-and-including-of-dates/#findComment-576757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.