从 MySQL 中检索时间为 HH:MM 格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13250531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:23:36  来源:igfitidea点击:

Retrieve time from MySQL as HH:MM format

mysqlsqldatetimetime

提问by ?т?

I used DATETIMEdatatype to store date and time in my Database. It saved date as

我使用DATETIME数据类型在我的数据库中存储日期和时间。它将日期保存为

YY-MM-DD HH:MM:SS (2012-11-06 10:45:48)  

I can retrieve the time from database as HH:MM:SSformat but I want to retrieve it in HH:MMformat.

我可以从数据库中以HH:MM:SS格式检索时间,但我想以HH:MM格式检索它。

How can I do this?

我怎样才能做到这一点?

回答by xdazz

Check the DATE_FORMATFunction.

检查DATE_FORMAT函数。

SELECT DATE_FORMAT(date_column, '%H:%i') FROM your_table

回答by Taryn

You will want to use DATE_FORMAT():

你会想要使用DATE_FORMAT()

select date_format(yourDateColumn, '%h:%i') yourTime
from yourtable

See SQL Fiddle with Demo

参见SQL Fiddle with Demo

回答by Rolice

SELECT DATE_FORMAT( NOW() ,  '%H:%i' ) AS time_column