In a MySQL table I have a date field which is in the format of YYYY-MM-DD. I also have a switch statement to filter the results depending on the value of a drop-down list (Jan, Feb, Mar etc). I have used the following switch statement:
switch ($dropdownValue) {
case "January":
mysql_query("SELECT * FROM counter WHERE date BETWEEN 2006-09-01 AND 2006-09-31");
break;
And that continues for each month.
But this doesn't display any dates no matter which month I select. I have a feeling it's the date itsself. Am I going to have to convert each date to a unix timestamp to perform the sort correctly?
You're sending the dates as string literals -> BETWEEN '2006-09-01' AND '2006-09-31'
otherwise they are treated as numbers, i.e. date between 1996 AND 1966
case "January":
mysql_query("SELECT * FROM counter WHERE date BETWEEN 2006-09-01 AND 2006-09-31");
break;
You do not store the result resource of that query. How do you fetch the data?
impulse() wrote:So MySQLs 'BETWEEN' is used for strings and not integers?
That's not what I've said.
If you do not mark your date literals it as strings they are treated as numbers and minus signs - this has nothing to do with between, it's how the mysql parser works. And the php parser as well.