从 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
Retrieve time from MySQL as HH:MM format
提问by ?т?
I used DATETIME
datatype 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:SS
format but I want to retrieve it in HH:MM
format.
我可以从数据库中以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
回答by Rolice
SELECT DATE_FORMAT( NOW() , '%H:%i' ) AS time_column