Can the MYSQL function STR-TO-DATE convert a string in this format 99-MMM-9999 (ex., '21-Sep-2014' to a date format? And what if that field is defined as 12 chars instead of the specific 11?
I tried this and it got NULLS.
You can, just setting proper format mask:
SELECT STR_TO_DATE('21-Sep-2014','%d-%M-%Y');
If you have 12 chars, set proper mask, sample:
SELECT STR_TO_DATE(' 21-Sep-2014',' %d-%M-%Y');
SELECT STR_TO_DATE(yourdatefield, '%m/%d/%Y')
FROM yourtable
You can also handle these date strings in WHERE clauses. For example
SELECT 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()
reference :- how to convert a string to date in mysql?
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format