如何从(00:00)的mysql数据库中显示小时和分钟只有Php?

时间:2016-12-28 20:43:56

标签: php mysql display hour minute

如何从(00:00)的mysql数据库中显示小时和分钟只有Php? 这是我的代码:

$query = "SELECT * FROM table";
$resualt = mysqli_query($conn, $query);

if (mysqli_num_rows($resualt) > 0)
{
    echo "<table class='tb'>";
    while($row = mysqli_fetch_assoc($resualt)){
        echo "<tr><td>" . $row['id']. "</td><td> " .$row['name']. " </td><td> " . $row['place']. " </td><td> " . $row['ddate']. " </td><td> " . $row['dtime']. " </td><td> ".$row['message']."</td></tr>";
    }
    echo `enter code here`"<table>";
}
else
{
    echo "there is no record.";
}

感谢

2 个答案:

答案 0 :(得分:2)

您通过MySQL查询时间

SELECT DATE_FORMAT(NOW(), '%H:%i')

例如

$query = "SELECT *, DATE_FORMAT(NOW(), '%H:%i') as time FROM table";

然后您可以通过$row['time'];

访问它

答案 1 :(得分:0)

假设你的桌子有一个日期时间栏,你可以像这样从中抽取小时和分钟......

 SELECT HOUR( `datecol` ) AS HOUR, MINUTE( `datecol` ) AS MINUTE FROM table WHERE BLAH=blah

您还可以选择其他内容,例如....

WEEK获取一年中的周数

WEEKDAY获取本周的日期名称...