[英]Mysql SELECT by date format as 24 hour
I am trying to select data from a table mysql
but I need to format a varchar
date column in a military format, but cannot get my desire output my query is below. 我正在尝试从表mysql
选择数据,但是我需要以军用格式格式化varchar
日期列,但无法获得我的查询输出,我的查询如下。
"SELECT STR_TO_DATE(`hour`, '%Y-%m-%d %k:%i') AS `time` FROM `dataTable`"
When I tried to echo the time below format appear. 当我尝试回显以下格式的时间时。
2017-09-21 00:00:00
My desire output is below which is in 24 hour format and removing the seconds, any suggestions would be great. 我的期望输出低于24小时格式,并删除秒,任何建议都很好。
2017-09-21 18:00
Use the Date_format
function of mysql. 使用mysql的Date_format
函数。
"SELECT DATE_FORMAT(`hour`, '%Y-%m-%d %H:%i') AS `time` FROM `dataTable`"
Explanation: 说明:
The STR_TO_DATE
function always return the date in the format of 2008-09-15 22:23:00 STR_TO_DATE
函数始终以2008-09-15 22:23:00的格式返回日期
SELECT STR_TO_DATE('Monday 15th September 2008 22:23:00', '%W %D %M %Y %H:%i:%s');
+----------------------------------------------------------------------------+
| STR_TO_DATE('Monday 15th September 2008 22:23:00', '%W %D %M %Y %H:%i:%s') |
+----------------------------------------------------------------------------+
| 2008-09-15 22:23:00 |
+----------------------------------------------------------------------------+
1 row in set (0.00 sec)
Check the above example: the second parameter in STR_TO_DATE
function is the format of the parameter 1 to tell the function that in which format parameter 1 is passed in the function. 检查上面的示例: STR_TO_DATE
函数中的第二个参数是参数1的格式,以告诉函数参数1以哪种格式传递给函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.