Dùng STR_TO_DATE() chuyển chuỗi sang date.
Cú pháp:
SELECT STR_TO_DATE(yourColumnName,'%d/%m/%Y') as anyVariableName from yourTableName.
Tạo bảng cột varchar, chèn: '26/11/2018', '27/11/2018', '2/12/2018', '3/12/2018'.
Truy vấn:
mysql> select STR_TO_DATE(IssueDate, '%d/%m/%Y') StringToDateFormatExample from DateFormatDemo;
Kết quả:
+---------------------------+ | StringToDateFormatExample | +---------------------------+ | 2018-11-26 | | 2018-11-27 | | 2018-12-02 | | 2018-12-03 | +---------------------------+ 4 rows in set (0.00 sec)