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

前端 未结 3 554
你的背包
你的背包 2021-01-01 11:05

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\"

相关标签:
3条回答
  • 2021-01-01 11:38
    SELECT DATE_FORMAT('2011-07-16 22:23:15', '%Y-%m-%d %H:%i');
    
    0 讨论(0)
  • 2021-01-01 11:42
    SELECT DATE_FORMAT(`date`, '%Y-%m-%d %H:%i') AS `formatted_date` FROM `table`;
    
    0 讨论(0)
  • 2021-01-01 11:45

    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 讨论(0)
提交回复
热议问题