timmah1 Posted December 15, 2008 Share Posted December 15, 2008 I need to select everything from the database of the current month the field in the database is orderDate (0000-00-00) What I have does not grab anything, it just says no sales, when I know there are at least 3 in there $month = date("m"); $sql = "SELECT * FROM memSales WHERE orderDate = '$month'"; $q = mysql_query($sql); $numrows = mysql_num_rows($q); if($numrows == 0) { echo "No sales for $month<br>"; echo "<a href='javascript: history.go(-1)'>Go Back</a>"; } while($a = mysql_fetch_assoc($q)){ echo $a['orderDate']."-".$a['price'];; } Anybody have any ideas? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/137038-solved-selecting-dates-from-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 15, 2008 Share Posted December 15, 2008 The current month also includes the current year. Otherwise a year or more from now, you will get data for more than one year. $sql = "SELECT * FROM memSales WHERE EXTRACT(YEAR_MONTH FROM orderDate) = EXTRACT(YEAR_MONTH FROM CURDATE())"; Link to comment https://forums.phpfreaks.com/topic/137038-solved-selecting-dates-from-database/#findComment-715727 Share on other sites More sharing options...
timmah1 Posted December 15, 2008 Author Share Posted December 15, 2008 Thank you very much Link to comment https://forums.phpfreaks.com/topic/137038-solved-selecting-dates-from-database/#findComment-715739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.