As it currently stands the code below only prints out the complete time stamp as in "2016-03-31 13:22:06" but i would only like to select the time only so "13:22:06" or even just the "13:22".
Just wanted to know how to split these up within a PDO select statement to only grab the time.
Thanks for your help in advance.
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM chatLogTwo";
foreach ($dbh->query($sql) as $row)
{
print $row['time'] .' - '. $row['message'] . '<br />';
}
You can try with date()
& strtotime()
-
print date('H:i:s', strtotime($row['time'])) .' - '. $row['message'] . '<br />';
Or change the query -
"SELECT DATE_FORMAT(`time`, '%H:%i:%s') `time`, message FROM chatLogTwo"
你也可以试试这个:
Select DATE_FORMAT(timecol,"%h:%i") AS time FROM chatLogTwo
Instead you can simply update your query into something like as
SELECT *,Date_format(`time`,'%H:%i') as only_time FROM chatLogTwo
and simply access it at your PHP code like as
echo $row['only_time'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.