参考 mysql数据库,日期格式转换及日期间的计算 date_format,date_sub
mysql中好像没有to_date()函数,但是可以用date_format()
date_format(date, '%Y-%m-%d')
具体可以这样使用
mysql> select date_format('20190808123456', '%Y-%m-%d %H:%i:%s');
+----------------------------------------------------+
| date_format('20190808123456', '%Y-%m-%d %H:%i:%s') |
+----------------------------------------------------+
| 2019-08-08 12:34:56 |
+----------------------------------------------------+
1 row in set (0.00 sec)
mysql> select date_format(date, '%Y-%M-%D') from test;
+-------------------------------+
| date_format(date, '%Y-%M-%D') |
+-------------------------------+
| 2020-August-20th |
| 2020-August-19th |
| 2020-August-21st |
| 2020-August-20th |
| 2020-August-21st |
+-------------------------------+
5 rows in set (0.00 sec)