Mike
Mike

Reputation:

Mysql Date SELECT

I'm trying to select all dates that haven't pass the current date. So for instance, I want to display every date after 2009-10-06 and NOT dates prior 2009-10-06.

Upvotes: 0

Views: 276

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 400912

What about something like this, if I understand correctly the question :

select *
from your_table
where your_date_field > '2009-10-06'

As @James Deville stated, you could use some function to get the current date, instead of hard-coding it in the query.

NOW() will get you date+time ; CURDATE() (or its aliases CURRENT_DATE() and CURRENT_DATE) will get you date :

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2009-10-06 19:35:36 |
+---------------------+
1 row in set (0.03 sec)

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2009-10-06 |
+------------+
1 row in set (0.01 sec)

So, in your case, something like this should do :

select *
from your_table
where your_date_field > curdate()

Upvotes: 4

Related Questions