gpt4 book ai didi

mysql - varchar m :d:Y H:i:s to date and datetime format conversion

转载 作者:行者123 更新时间:2023-11-29 18:04:51 25 4
gpt4 key购买 nike

我已将 varchar(modefied_date) 转换为日期和日期时间格式,例如 varchar column '26-12-2017 12:21:12' 转换为 date '2017-12 -26' 和 日期时间 '2017-12-26 12:21:12'

位置表

id modefied_date         location
----------------------------------
1 26-12-2017 12:21:12 salem
2 26-12-2017 12:26:52 erode
3 26-12-2017 12:32:12 coimbatore

modefied_date 是 varchar data_type

我尝试这个查询

查询1:

select location,date_format(modefied_date,'%Y-%m-%d %H:%i %p') AS datetime from locatio_table where date(modefied_date) ='2017-12-26'

此查询显示空结果

查询2:

select location,date_format(modefied_date,'%Y-%m-%d %H:%i %p') AS datetime from locatio_table

此查询显示结果为'null'的位置

最佳答案

查询1:

mysql> select location,date_format(modefied_date,'%Y-%m-%d %H:%i %p') AS datetime from locatio_table where date(modefied_date) ='2017-12-26';
+----------+---------------------+
| location | datetime |
+----------+---------------------+
| salem | 2017-12-26 12:21 PM |
+----------+---------------------+
1 row in set (0.00 sec)

查询2:

mysql> select location,date_format(modefied_date,'%Y-%m-%d %H:%i %p') AS datetime from locatio_table;
+----------+---------------------+
| location | datetime |
+----------+---------------------+
| salem | 2017-12-26 12:21 PM |
+----------+---------------------+
1 row in set (0.00 sec)

您的查询给出了预期的输出。所有结果均不为 null/空。

关于mysql - varchar m :d:Y H:i:s to date and datetime format conversion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47974760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com