dhope Posted July 31, 2011 Share Posted July 31, 2011 Hi, I currently have a simple mysql statement which pulls out all of the fields between two given dates. The statement works fine until you increase the end date. Code... $start_date = "01/07/2011"; $end_date = "15/07/2011"; $result = mysql_query("SELECT * FROM sales WHERE sale_date BETWEEN '$start_date' AND '$end_date'"); ------- This works fine up until I increase the end date above the 15th then it seems to drag everything in regardless of the date. Any ideas, is there anyway I can improve this code to make it work? Thank you Link to comment https://forums.phpfreaks.com/topic/243379-between-two-dates/ Share on other sites More sharing options...
fenway Posted July 31, 2011 Share Posted July 31, 2011 That's because you're not using SQL-99 dates. Either convert the dates in PHP, or use STR_TO_DATE() to get them into YYYY-MM-DD. Link to comment https://forums.phpfreaks.com/topic/243379-between-two-dates/#findComment-1249788 Share on other sites More sharing options...
localtechguy Posted August 1, 2011 Share Posted August 1, 2011 Or you might be able to do $result = mysql_query("SELECT * FROM sales WHERE sale_date >= '$start_date' AND sale_date <= '$end_date'"); Link to comment https://forums.phpfreaks.com/topic/243379-between-two-dates/#findComment-1250413 Share on other sites More sharing options...
fenway Posted August 2, 2011 Share Posted August 2, 2011 Or you might be able to do $result = mysql_query("SELECT * FROM sales WHERE sale_date >= '$start_date' AND sale_date <= '$end_date'"); No, you won't be able to do that until you're using proper date strings. Link to comment https://forums.phpfreaks.com/topic/243379-between-two-dates/#findComment-1250660 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.