hoopplaya4 Posted October 20, 2008 Share Posted October 20, 2008 Hi, I'm pulling several times from a MySQL database and putting into a table format in PHP. However, the times right now come up as: 16:00:00, as opposed to 4:00 PM. How can I query the database and convert it into a readable time? Here's a quick look at my code: <?php $loopCount = 0; $sql = "SELECT classID, classTitle, classStart, classEnd, classDays"; $sql .= " FROM tblCourses WHERE (usrID = " . $_SESSION['sessUsrID'] . ")"; $sql .= " ORDER BY classID"; require("../connection.php"); $rs=mysql_db_query($DBname,$sql,$link); if ($rs) { while ($row=mysql_fetch_array($rs)){ $daysSTR = $row['classDays']; $chars = array("M", "T", "W", "Th", "F", "S", "Su"); $nums = array("1", "2", "3", "4", "5", "6", "7"); $daysSTR = str_replace($nums, $chars, $daysSTR); $daysSTR = str_replace(",", "", $daysSTR); $mysqltime = date ("Y-m-d H:i:s", $phptime); print(" <tr>\n"); print(" <td>" . $row['classTitle'] . "</td>\n"); print(" <td>" . $row['classStart'] . "</td>\n"); print(" <td>" . $row['classEnd'] . "</td>\n"); print(" <td>$daysSTR</td>\n"); print(" <td><a href='editEvents.php?action=edit&num=" . $row['classID'] . "'>Edit</a> "); print("<a href='editEvents.php?action=delete&num=" . $row['classID'] . "'>Delete</a></td>\n"); print(" </tr>\n"); $loopCount += 1; } //end while if ($_GET["msg"] == 1){print("<tr>\n<td colspan=5><font color=red>Event Edited</td>\n</tr>\n");} if ($_GET["msg"] == 2){print("<tr>\n<td colspan=5><font color=red>Event Deleted</td>\n</tr>\n");} print("</table>\n</td>\n</tr>\n</table>"); mysql_close($link); } // end if ($rs) else { // No Events found print("No Events found"); mysql_close($link); } // end else ($rs) Thanks in advance for your help!! Link to comment https://forums.phpfreaks.com/topic/129156-convert-mysql-to-to-readable-time/ Share on other sites More sharing options...
Twister1004 Posted October 20, 2008 Share Posted October 20, 2008 for an 12Hr clock, 59min, and AM or PM, this would be the code. (You will probably have to change it to fit in, this is just the basic code for it.) <?php date("h i A"); ?> Link to comment https://forums.phpfreaks.com/topic/129156-convert-mysql-to-to-readable-time/#findComment-669622 Share on other sites More sharing options...
xtopolis Posted October 20, 2008 Share Posted October 20, 2008 You can do it from mysql, http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html However, depending on when the classes are offered, wouldn't it be better to leave it in military time in case a class is at 8am and say 8pm(20:00)? Link to comment https://forums.phpfreaks.com/topic/129156-convert-mysql-to-to-readable-time/#findComment-669623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.