开发者

How to select date and time without the seconds in mysql?

开发者 https://www.devze.com 2023-03-20 23:03 出处:网络
How do I select d开发者_StackOverflowate and time without the seconds in mysql from a column with date value in a table ?

How do I select d开发者_StackOverflowate and time without the seconds in mysql from a column with date value in a table ? "YYYY-MM-DD HH:MM:SS" should be "YYYY-MM-DD HH:MM"


SELECT DATE_FORMAT(`date`, '%Y-%m-%d %H:%i') AS `formatted_date` FROM `table`;


SELECT DATE_FORMAT('2011-07-16 22:23:15', '%Y-%m-%d %H:%i');


The proper solution is zero out seconds - and - preserve data type:

SELECT `datetime` - INTERVAL EXTRACT(SECOND FROM `datetime`) SECOND
FROM `some table`

If your datetime column contains microseconds then use this variant:

SELECT `datetime` - INTERVAL EXTRACT(SECOND_MICROSECOND FROM `datetime`) SECOND_MICROSECOND
FROM `some table`

SQL Fiddle

In theory, it should be faster than examples using date formatting functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消