Reputation: 1
How can I display hour and minute only Php from mysql database like(00:00)? Here is my code:
$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.";
}
thanks
Upvotes: 0
Views: 1704
Reputation: 1260
Assuming your table has a datetime column, you can pluck the hour and minutes from it like this...
SELECT HOUR( `datecol` ) AS HOUR, MINUTE( `datecol` ) AS MINUTE FROM table WHERE BLAH=blah
You can also select other things like ....
WEEK
to get the week number of the year
WEEKDAY
to get the day name of the week...
Upvotes: 0
Reputation: 2534
You query the time through MySQL with
SELECT DATE_FORMAT(NOW(), '%H:%i')
For example
$query = "SELECT *, DATE_FORMAT(NOW(), '%H:%i') as time FROM table";
Then you can access it through $row['time'];
Upvotes: 2