I have a form where you can fill out Firstname, Lastname etc. And the information will get sent to a database along with the date (yyyy-mm-dd hh-mm-ss). In my table it will display the full date but i only want it to display the hours and seconds. But year, month etc. in the database.
So how do i only fetch the hours and minutes from the database and display it in a table?
HTML:
<tr>
<th>dato</th>
<th>Båtnr</th>
<th>Fornavn</th>
<th>Etternavn</th>
<th>Tid</th>
<th>Kr</th>
</tr>
PHP:
<?php
$sok = @$_POST['searchh'];
$sql = "SELECT dato, baatnr, fornavn, etternavn, tid, kr FROM utleie WHERE baatnr LIKE '%$sok%' or fornavn LIKE '%$sok%' or etternavn LIKE '%$sok%' or tid LIKE '%$sok%'";
$result = $conn-> query($sql);
if ($result-> num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>".
$row["dato"] ."</td><td>".
$row["baatnr"] ."</td><td>".
$row["fornavn"] ."</td><td>".
$row["etternavn"] ."</td><td>".
$row["tid"] ."</td><td>".
$row["kr"] ."</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
database date enter image description here
5
Answers
use
date_format()
of mysqldate_format(column,'%h:%i') as column
You can use time() function for getting the current hour and minutes:
You will have to split your date value which you will get from the query result.
For splitting the date in hours and minutes you can use the explode function.
Ex :
Here I have splitted the date field using ” ” (space) and fetched the second value of array.
Note : this will be handled on the php end and not on the database part because in your database you have already inserted the value in timestamp format.
or
Hope This Help
you can do it without any change from database side.
you can use php
date
function to manipulate it like:this will convert your database date to HH:mm format.