-1

I want to display data from the sql table , the datatype is datetime(6) that is data size 6 bytes. Now when I display the data in a html table with input tag andtype text I get the datetime format with trailing zeros. I want to display the datetime format without trailing zeroes.I present the codes below.

codes on the input form where the data is collected.

<li>
   <label for="date-time">Access Date And Time</label>
   <input name="date-time" type="datetime-local" id="date-time"/>
</li>

This is the code for displaying the data.

<?php
include('/templates/header.php');
$host = "localhost"; // Host name 
$username = "root"; // Mysql username 
$password = ""; // Mysql password 
$db_name = "datacentre"; // Database name 
$tbl_name = "data_centre_users"; // Table name 
$server_name = "localhost";

// Create connection
$con = new mysqli($server_name, $username, $password, $db_name, 3306);
if($con->connect_error){
   die("Connection failed: ".$con->connect_error);
}

// Check connection
if($con->connect_error){
 die("Connection failed: ".$conn->connect_error);
}

$sql = "SELECT * FROM $tbl_name";
$result = $con->query($sql);
?>

<section id="sidebar">

</section>

<section id="content">

<div id="scroll-table">
<table >
<caption>
           List data from mysql
            </caption>
            <tr>
                <th class="center"><strong>ID</strong></th>
                <th class="center"><strong>FirstName</strong></th>
                <th class="center"><strong>Lastname</strong></th>
                <th class="center"><strong>Request</strong></th>
                <th class="center"><strong>Purpose</strong></th>
                <th class="center"><strong>Description</strong></th>
                <th class="center"><strong>Booking Time</strong></th>
                <th class="center"><strong>Access Time</strong></th>
                <th class="center"><strong>Exit Time</strong></th>
                <th class="center"><strong>Approved</strong></th>
                <th class="center"><strong>Approved By</strong></th>
                <th class="center"><strong>Update</strong></th>
                <th class="center"><strong>Delete</strong></th>
            </tr>
            <?php
            if($result->num_rows > 0){
                // output data of each row
                while($rows = $result->fetch_assoc()){ ?>
                    <tr>
                        <td class="center"><?php echo $rows['id']; ?></td>
                        <td class="center"><?php echo $rows['fisrt_name']; ?></td>
                        <td class="center"><?php echo $rows['last_name']; ?></td>
                        <td class="center"><?php echo $rows['request']; ?></td>
                        <td class="center"><?php echo $rows['purpose']; ?></td>
                        <td class="center"><?php echo $rows['description']; ?></td>
                        <td class="center"><?php echo $rows['booking_time']; ?></td>
                        <td class="center"><?php echo $rows['access_time']; ?></td>
                        <td class="center"><?php echo $rows['exit_time']; ?></td>
                        <td class="center"><?php echo $rows['approved']; ?></td>
                        <td class="center"><?php echo $rows['approved_by']; ?></td>
                        <td class="center" ><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td>
                        <td class="center" ><a href="delete.php?id=<?php echo $rows['id']; ?>">delete</a></td>
                    </tr>
                        
                    <?php
                }
            }
            ?> 
</table>
</div>
</section>


<aside></aside>

<?php
$con->close();

include('/templates/footer.php');
?>

this is the web page.

enter image description here

faisal abdulai
  • 3,739
  • 8
  • 44
  • 66
  • 1
    Possible duplicate: http://stackoverflow.com/questions/136782/convert-from-mysql-datetime-to-another-format-with-php – t.h3ads Jul 27 '15 at 11:49
  • Correct me if I'm wrong, but I think `datetime(6)` represents 6 digits precision for the time fraction. – frz3993 Jul 27 '15 at 11:58

1 Answers1

1
$timestamp = strtotime($rows['booking_time']);
echo date('Y-m-d H:i:s',$timestamp);

Should format the date

Andre
  • 385
  • 1
  • 13