MySQL 如何在mysql中没有秒的情况下选择日期和时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6718759/
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
How to select date and time without the seconds in mysql?
提问by Sjemmie
How do I select date 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"
如何从表中具有日期值的列中选择没有 mysql 中的秒数的日期和时间?“YYYY-MM-DD HH:MM:SS”应该是“YYYY-MM-DD HH:MM”
回答by Ruslan Polutsygan
SELECT DATE_FORMAT(`date`, '%Y-%m-%d %H:%i') AS `formatted_date` FROM `table`;
回答by CristiC
SELECT DATE_FORMAT('2011-07-16 22:23:15', '%Y-%m-%d %H:%i');
回答by Salman A
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`
In theory, it should be faster than examples using date formatting functions.
理论上,它应该比使用日期格式化函数的示例更快。