0

Hi, i'm wondering how do i convert a TIMEDIFF to a string? Basically i have a database with a "tomorrow time" (timestamp + 24 hours) in it, which shows the time 24 hours from the exact time that the data enters the database. I have the "time left" printing out on screen, which is basically the difference between the "tomorrow time" and the "Current Time" (SYSDATE()). This is the code that is printing out on screen.

<?php
			$con = mysql_connect("xxx","xxx","xxx");
			if (!$con)
			 {
			 die('Could not connect: ' . mysql_error());
			 }

			mysql_select_db("xxx", $con);

			$result = mysql_query("SELECT tomorrowtime, SYSDATE(), TIMEDIFF(tomorrowtime, SYSDATE()) AS timeleft FROM proposal"); 

			echo "<table id='myTable' cellpadding='0'>
			<thead>
			<th axis='string'>Tomorrow Time</th>
			<th axis='string'>Current Time</th>
			<th axis='string'>Time Left</th>
			</thead>";

			while($row = mysql_fetch_array($result))
			 {
			 echo "<tr>";
				echo "<td>" . $row['tomorrowtime'] . "</td>";
				echo "<td>" . $row['SYSDATE()'] . "</td>";
				echo "<td>" . $row['timeleft'] . "</td>";
			echo "</tr>";
				echo "</tbody>";
			 }
			echo "</table>";

			mysql_close($con);
			?>

The "Time Left" prints out in the form of "19:02:25". How do i convert this to a string so that it says 19 hours, 2 minutes and 25 seconds - or just 19 hours 2 minutes.

Any help would be greatly appreciated.

Thank you

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by blocblue
0

Hi,

You could use the date method...

echo date( 'G \hours, i \minutes, s \seconds', strtotime($row['timeleft']) );

You'll need to escape the characters from "hours", "minutes" and "seconds" which are date arguments... but you get the gist I'm sure...

R.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.