I’m trying to get all rows from a table that lie between two dates. As a test, I set my two variables so that everything between 2000 and 2020 would show, but I ran into an error:
Unknown column 'DATE_START_SELECTED' in 'where clause'
This is the code I used:
$DATE_START_SELECTED = new DateTime('2000-01-01 05:59:00');
$DATE_END_SELECTED = new DateTime('2020-03-15 09:30:00');
$query = 'SELECT * FROM events WHERE DATE_START_SELECTED <= start_datetime AND end_datetime < DATE_END_SELECTED';
$result = mysql_query($query) or die(mysql_error());
Any idea why? Thanks 🙂
You are using Object
The best bet is you have to convert it to string, like
Then, change the SQL to
DATE_START_SELECTEDis string,in SQL mode will refer to column name, table name or database name
while
$DATE_START_SELECTEDis PHP variables