How can I display hour and minute only Php from mysql database like(00:00)?

1.6k views Asked by At

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

2

There are 2 answers

2
user3606329 On

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'];

0
Duane Lortie On

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...