I need to do a query on a MySQL table. I need to select records that are greater than a particular date. the problem is, the field was created as a varchar. how can I do a comparison of dates in this case?
Printable View
I need to do a query on a MySQL table. I need to select records that are greater than a particular date. the problem is, the field was created as a varchar. how can I do a comparison of dates in this case?
.
Are the values all in exactly the same format? if not you'll probably have major hassle working it out!
What you need to do is somehow split the field into the three parts (d, m, and y), preferably in a numeric format.
Then you can do a where clause like the following:
Code:WHERE y > specific_year
OR (y = specific_year
AND ( (m > specific_month)
OR ( (m= specific_month)
AND (d> specific_day)
)
)
)
OK...
1) Find out the convert to date function in MySql's Sql statement - concatinate the three fields and use...
2) Concatinate the three fields together yyyymmdd (note the months and days must be in two digits with leading 0) - sort and see if that helps with filtering.
Vince