PDA

View Full Version : TIME_FORMAT Issues


ksduded
08-01-2008, 10:04 PM
i am using the TIME_FORMAT command in PHP to extract the time from one of the fields, which list it in 0-23 hour format and change it to 1-12 AM PM format.

This is for a TV Schedule, so for example if one program has the entry 00:00:00 then it means it is 12:00 AM. It works fine that way.

But if there is an entry for 00:30:00, it should say 12:30 AM, but it still says 12:00 AM and down the road it starts posting a value of 03:30:00 as 2:30 AM.

I am not sure how it can post that value, as there is not even any value in the database. And I have not applied any calculations in the PHP coding.. its just picking up the time from one of the fields.

$resulttime = mysql_query("SELECT *, TIME_FORMAT( prog_time, '%l:%i %p') AS prog_time2 from rushhd_schd");

PHP Code posting the values from the database

while($info = mysql_fetch_array($result))
{
if($info['prog_date'] == $selecteddate) // if the selected date is equal to the date of the record
{
$ptime = mysql_fetch_array($resulttime);
$programtime = $ptime['prog_time2']; // saving the program time in a new array for formatting purposes


// checking to see if an episode has a name or not and managing the line breaks accordingly
if($rowcolor == '1') // switch the row color for every alternate row
{
if(trim($info['prog_episodename']) == '') // to give the respective breaks if there is a record for episode name
{
echo "<tr><td valign=top bgcolor=#28414c width=60><font color=#a6b9c5>".$programtime."<BR>".$info['prog_timezone']."</font></td> ";
echo "<td bgcolor=#102733 width=390><B><font color=#e5731a>".$info['prog_programname']."</font></b><BR><BR><font color=#89969b>".$info['prog_episodedesc']."</font></td></tr>";
$rowcolor = '0';
}
else

Thanks in advance for any help. Will greatly appreciate it.

CFMaBiSmAd
08-01-2008, 10:18 PM
The posted code is using $resulttime for the result resource in the query and $result in the mysql_fetch_array statement for the while() loop. Are you sure the two different result sets correspond?

ksduded
08-05-2008, 07:38 PM
The posted code is using $resulttime for the result resource in the query and $result in the mysql_fetch_array statement for the while() loop. Are you sure the two different result sets correspond?

$result is define as

$result = mysql_query("SELECT * from rushhd_schd"); // storing the result of the whole table in the string $result

It takes all the values from the table, while $resulttime is for reformating the prog_time field (which is a time field)