Question : How do I compare two dates in MySQL if one is a text field?

I've inherited a database where there is a field that contains a date, but rather than using the DATE type it's a VARCHAR. The dates are formatted like 07/05/2010.

Now they want to compare the date field to today's date to see if it's already passed. I'd like to do this in the MySQL query -- rather than getting all the date records and doing a ColdFusion Query of Querys later -- but I can't seem to come up with the correct code to do so. Below is what I'm using... can you tell me where I'm going wrong?

Thank you!
1:
2:
3:
SELECT field1, field2, date_field
FROM my_table
WHERE DATE_FORMAT(date_field,'%m/%d/%Y') < DATE_FORMAT(CURDATE(),'%m/%d/%Y')

Answer : How do I compare two dates in MySQL if one is a text field?

use str_to_date() to convert the string to a date:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_str-to-date


SELECT field1, field2, date_field
FROM my_table
WHERE STR_TO_DATE(date_field,'%m/%d/%Y') < CURDATE()
Random Solutions  
 
programming4us programming4us