string column which acts as a date and I want to select it as a date. Is it possible?
My sample data format would be;
month/day/year -> 12/31/2011Cevap:SELECT STR_TO_DATE(yourdatefield, '%m/%d/%Y')
FROM yourtable
You can also handle these date strings in WHERE clauses. For exampleSELECT whatever
FROM yourtable
WHERE STR_TO_DATE(yourdatefield, '%m/%d/%Y') > CURDATE() - INTERVAL 7 DAYS
You can handle all kinds of date / time layouts this way. Please refer to the format specifiers for the DATE_FORMAT() function to see what you can put into the second parameter to STR_TO_DATE()http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
Hiç yorum yok :
Yorum Gönder