How can I get the rows in a table where today\'s date is between (inclusive) two DATE columns of that row? For example, take these two columns of a table:
You can add a condition as follows
DATE(NOW()) between date1 and date2
If you have date (not datetime) columns, use CURTIME() or DATE(NOW()), never NOW() as CesarC correct wrote and you can use BETWEEN.
SELECT * FROM table WHERE CURTIME() BETWEEN from_date AND to_date
Just use the SQL now() function to compare the date columns like so:
SELECT * from table where now() >= from_date and now() <= to_date
You will find a lot of people using between operator, but I prefer using a simple AND operator.
I do that because although the between operator IS inclusive, simple dates (2012-04-10) can be counted as being midnight, and will thus not be inclusive.
So this should work just fine and will always include the boundaries of the date range:
SELECT * FROM table WHERE from_date <= '2012-04-10' AND to_date >= '2012-04-10'