SELECT MySQL rows where today the date is between two DATE columns

How can I get rows in a table where today the date is between the (inclusive) two DATE columns of that row? For example, take these two columns of a table:

enter image description here

How can I get the first and second lines of April 10 or the 3rd line of the 25th (inclusive, as I said)?

Any help would be greatly appreciated. Thanks in advance!

+7
source share
3 answers

You will find many people using the operator, but I prefer to use the simple operator I.

I do this because although between the IS operator is included, simple dates (2012-04-10) can be considered midnight and therefore will not include.

So this should work fine and will always include date range bounds:

Statement

SELECT * FROM table WHERE from_date >= '2012-04-10' AND to_date <= '2012-04-10' 
+13
source

You can add a condition as follows

 DATE(NOW()) between date1 and date2 
+15
source

Just use the SQL function now () to compare date columns like this:

 SELECT * from table where now() >= from_date and now() <= to_date 
+6
source

All Articles