如何从Mysql数据库获取小时和分钟的时间格式?

如何从Mysql数据库获取小时和分钟的时间格式?

问题描述:

I am using codeigniter and got problem doing properly the query.

$query = $this->db->query('SELECT datetime ...');
$resultdata['results'] = $query->result_array();

foreach($results as $result)
{
    echo "<tr>";
    echo "<td>".$result['datetime']."</td>";
    echo "</tr>";
}

This code make result of the date in this format: 2015-04-11 02:45:19. How can I do the result only with HOURS and MINUTES? Thank you.

Just use MySQL's DATE_FORMAT() function:

$query = $this->db->query('SELECT DATE_FORMAT(datetime, "%H:%i") as `time` ...