简体   繁体   English

将 MySQL 中的日期转换为 yyyy-mm-dd

[英]Convert date in MySQL to yyyy-mm-dd

I have a DB where the dates are stored as varchar mm/dd/yyy (12/10/2022) But I can't figure out how to convert them to yyyy-mm-dd (2022-12-10 or 2022/12/10)我有一个数据库,其中日期存储为 varchar mm/dd/yyy (12/10/2022) 但我不知道如何将它们转换为 yyyy-mm-dd(2022-12-10 或 2022/12 /10)

This doesn't work SELECT DATE_FORMAT("06/15/2022", "%Y-%m-%d");这不起作用 SELECT DATE_FORMAT("06/15/2022", "%Y-%m-%d");

PS I also want to issue a SQL command to change all the dates in the DB PS 我还想发出 SQL 命令来更改数据库中的所有日期

You can convert a string to a date with the function str_to_date():您可以使用 function str_to_date() 将字符串转换为日期:

select str_to_date('12/10/2022',"%m/%d/%Y");

https://www.w3schools.com/Sql/func_mysql_str_to_date.asp https://www.w3schools.com/Sql/func_mysql_str_to_date.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM