varchar m:d:Y H:i:s到mysql的日期和日期时间格式转换

时间:2017-12-26 06:32:33

标签: mysql mysqli phpmyadmin

  

我使用phpmyadmin,我已将varchar(modefied_date)转换为日期   和datetime formate一样 varchar column ' 26-12-2017 12:21:12'到日期   ' 2017年12月26日'和日期时间' 2017-12-26 12:21:12'

     

locatio_table

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

我尝试这个查询

QUERY1:

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

此查询显示空结果

query2:

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

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

1 个答案:

答案 0 :(得分:0)

查询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 / empty。