Retrieve time from MySQL as HH:MM format

白昼怎懂夜的黑 提交于 2019-12-09 17:00:52

问题


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

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.

How can I do this?


回答1:


Check the DATE_FORMAT Function.

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



回答2:


You will want to use DATE_FORMAT():

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

See SQL Fiddle with Demo




回答3:


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


来源:https://stackoverflow.com/questions/13250531/retrieve-time-from-mysql-as-hhmm-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!