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');
}
解决方案
SELECT TIME_FORMAT('14:30:00', '%h:%i %p'); /* 02:30 PM */
Change your PHP to something like this:
$finalresult = mysql_query("SELECT Field1, Field2, TIME_FORMAT(DateField, '%h:%i %p') AS TheTime FROM events WHERE clubID IN (" . implode(',', $clubIDs) . ") ORDER BY date ASC, TIME(startTime) ASC");
This involves getting rid of * and specifying each field you want.
这篇博客讨论了如何将MySQL中hh:mm:ss格式的时间转换为12小时制,并在PHP查询中去除秒数。作者提供了SQL查询示例,通过使用TIME_FORMAT函数来格式化时间,并建议在PHP代码中直接进行查询优化,明确指定需要的字段。
174万+

被折叠的 条评论
为什么被折叠?



