I’m trying to request any records from a table that appear on or after today’s date, using a single query.
All the dates for each record are stored in separate columns e.g.. – one for month, one for year, and one for day.
obviously i’ve been getting all records that occur after the year in today’s date
$sql = "SELECT * FROM table WHERE year>=".$year_today."
ORDER BY year, month, day";
Then i’ve been trying to filter that down a bit, by using:
$sql = "SELECT * FROM table
WHERE year>=".$year_today." && month>=".$month_today."
&& day>=".$day_today."
ORDER BY year, month, day";
And in order to test it, i created a record in the database with yesterdays date, yet, this record still appears in the list of returned records. What am i doing wrong? 🙁
I don’t know if you can use "&&" instead of "AND" in your context – maybe try changing your SQL to use
EDIT :
as an extension to Nick’s answer, to make the sql behave correctly you could code :
…but this starts to get a whole lot messier than converting to dates and using date comparison
EDIT2:
but then again, if these columns are indexed, the indexes might be used. It’s still a lot more effort to code SQL this way if performance using conversion to dates is totally acceptable.