I need to convert 19/06/2021 21:06:55
to a MySQL date format. I tried
SELECT DATE_FORMAT("19/06/2021 21:06:55", "%Y-%m-%d %H:%i:%s") as reg_date FROM users
but am getting an error? What path should I follow to achieve this?
It should be like this:
2021-06-19 21:06:55
DATE_FORMAT
formats ISO dates to other formats, but what you have is not an ISO date.
Use STR_TO_DATE()
to convert the string to a date which is already in the format that you want:
SELECT STR_TO_DATE('19/06/2021 21:06:55', '%d/%m/%Y %H:%i:%s') AS reg_date FROM users
You need STR_TO_DATE
SELECT STR_TO_DATE("19/06/2021 21:06:55", "%d/%m/%Y %H:%i:%s") as reg_date
Which returns '2021-06-19 21:06:55'
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.