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?
我怎样才能做到这一点?
3 个解决方案
#1
12
Check the DATE_FORMAT Function.
检查DATE_FORMAT函数。
SELECT DATE_FORMAT(date_column, '%H:%i') FROM your_table
#2
6
You will want to use DATE_FORMAT()
:
您将需要使用DATE_FORMAT():
select date_format(yourDateColumn, '%h:%i') yourTime
from yourtable
请参阅SQL Fiddle with Demo
#3
4
SELECT DATE_FORMAT( NOW() , '%H:%i' ) AS time_column
#1
12
Check the DATE_FORMAT Function.
检查DATE_FORMAT函数。
SELECT DATE_FORMAT(date_column, '%H:%i') FROM your_table
#2
6
You will want to use DATE_FORMAT()
:
您将需要使用DATE_FORMAT():
select date_format(yourDateColumn, '%h:%i') yourTime
from yourtable
请参阅SQL Fiddle with Demo
#3
4
SELECT DATE_FORMAT( NOW() , '%H:%i' ) AS time_column