Jump to content

[SOLVED] selecting dates from database


timmah1

Recommended Posts

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

 

 

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())";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.