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
source share
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'or YYYYMMDD, depending on whether the function is used in a string or numeric context.


( ), now():

'YYYY-MM-DD HH:MM:SS' YYYYMMDDHHMMSS.uuuuuu

+4
SELECT * FROM MyTable WHERE MyDateCol < CURDATE()
+2

If MySQL supports SYSDATE, you should use this instead of NOW () or CURDATE (), since it is more standard.

SELECT * FROM MyTable WHERE MyDateCol < SYSDATE;
+2
source

Use NOW():

SELECT * FROM MyTable WHERE MyDateCol < NOW()
+1
source

All Articles