I have a MySQL table that looks something like this:
+-----+------------+
| id | enddate |
+------------------+
| 1 | 2012-06-30 |
+------------------+
| 2 | 2012-07-05 |
+------------------+
| 3 | 2012-07-02 |
+------------------+
On my website I would like to print out all rows who has a date that is between the range:
Today's date (I mean not fixed, but the date when the query is beeing run) and 2 weeks ahead.
So, using the above example only row 1 and 3 would be printed.
Anyone got a solution for this?
I think you need the BETWEEN comparison operator and some simple date functions:
WHERE enddate BETWEEN CURDATE() AND ADDDATE(CURDATE(), INTERVAL 14 DAY);
http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html#operator_between
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_adddate