Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get time format with hours and minutes from Mysql database?

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.

like image 859
Juraj Macák Avatar asked Apr 11 '15 01:04

Juraj Macák


1 Answers

Just use MySQL's DATE_FORMAT() function:

$query = $this->db->query('SELECT DATE_FORMAT(datetime, "%H:%i") as `time` ...
like image 127
John Conde Avatar answered Nov 10 '22 19:11

John Conde