STR_TO_DATE function return null in mysql

时间:2015-10-06 08:20:17

标签: php mysql

SELECT STR_TO_DATE(LEFT(booking_date , 10), '%c/%e/%Y') from mycase

The booking_date is my field and contain data like 01-10-2015 Evening ( 3PM - 6PM ).

And i want to first get the date and after that i want to convert that into date type in MySQL.

1 个答案:

答案 0 :(得分:0)

You need to change / to - in the str_to_time function since your input dates are in the format 01-10-2015

mysql> SELECT STR_TO_DATE(LEFT('01-10-2015 Evening ( 3PM - 6PM )' , 10), '%c-%e-%Y') as d ;
+------------+
| d          |
+------------+
| 2015-01-10 |
+------------+

SELECT STR_TO_DATE(LEFT(booking_date , 10), '%c-%e-%Y') from mycase