Jump to content

Convert MySQL To to Readable Time


hoopplaya4

Recommended Posts

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

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)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.