MySQL - SELECT WHERE date <X
How to do it in MySQL?
SELECT * FROM MyTable WHERE MyDateCol < TODAY()
I knew a lot about this topic and actually didn’t find anything except to “look at the dates of MySQL dates,” which does not explain it easily enough.
I know that I can do the following, which is indirect:
SELECT * FROM MyTable WHERE MyDateCol BETWEEN (0000-00-00) AND TODAY()
+5
4 answers
In MySQL, you have a curdate()funciton that will give you a date today.
So something like this should do:
select *
from your_table
where your_date_column < curdate()
Quoting the manual page of this function:
Returns the current date as a value in
'YYYY-MM-DD'orYYYYMMDD, depending on whether the function is used in a string or numeric context.
( ), now():
'YYYY-MM-DD HH:MM:SS'YYYYMMDDHHMMSS.uuuuuu
+4