I am trying to migrate data from one table to other. The issue is my target table has type date yyyy-mm-dd where as the source table has type varchar mm/dd/yy I tried a few thing but seems none worked.
I am trying this but seems to give null
select year((datecreated)) * 10000 + month((datecreated)) * 100 + day((datecreated)) from employee
Here employee is my table and datecreated is my column.
If someone has come across this please let me know how to fix it.
You can try the STR_TO_DATE
to convert a string to a date:
SELECT STR_TO_DATE(datecreated,'%m/%d/%Y') as date
FROM employee
Date format specifications (%m, etc) can be found here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.