My time in mysql is in the form hh:mm:ss How can I convert that to 12 hour time and also remove the seconds, because they are all 00.
ex:
14:30:00
mysql
$finalresult = mysql_query("SELECT * FROM events WHERE clubID IN (" . implode(',', $clubIDs) . ") ORDER BY date ASC, TIME(startTime) ASC");
while($finalrow = mysql_fetch_assoc($finalresult)) {
$originaltime = $finalrow['startTime'];
$newtime = TIME_FORMAT($originaltime, '%h:%i %p');
}
Use TIME_FORMAT:
Change your PHP to something like this:
This involves getting rid of
*
and specifying each field you want.If it's a
TIME
type, you can use theTIME_FORMAT
function.To get the 12-hour time, without seconds:
A time of 14:24:38 will come out as
2:24
.If you need the AM/PM designation now that you've converted to a 12-hour clock, simply add the
%p
format code:For this, a time of 14:24:38 will come out as
2:24 PM
.