Issue
I'm just starting to learn php and I've tried to research an answer to this but I can't find an answer that fits my situation. Remember, I'm a noob so please explain in detail.
Webpage where results are shown: https://fireytech.com/FireytechDatabase/hello.php
I have a php select query that pulls a field from my mysql database where a date / timestamp is saved. When I get the echo results of the query in my html form, it displays this date field in this format: 2022-01-31 00:00:00. I would like it to show as: 01/31/2022 (no time). Below is my form's code. How would I change date format for my "DateReceived" and "DateLastEdited" fields?
<?php
require '../../db_php/dbconnection.php';
$sql = "SELECT * FROM
Tickets
Left JOIN
Clients
ON Tickets.CustomerNumber=Clients.CustomerNumber
JOIN Contacts
ON Contacts.ContactID=Clients.CustomerNumber
JOIN Equipment
ON Equipment.ContactID=Clients.CustomerNumber
WHERE Equipment.PRINT = '-1' AND Contacts.DispatchContact = '-1' AND TicketStatus = 'Active' AND NOT TicketSubStatus = 'CUSTOMER PICKUP' AND NOT TaskSubType = 'ON-SITE'
";
$result = $conn->query($sql);
echo"<table border='1'>";
echo "<tr><td>Ticket Type</td><td>Ticket Number</td><td>Date Received</td><td>Last Edited</td><td>Last Name</td><td>Followup By</td><td>Sub Status</td><td>Repair Type</td><tr>";
if ($result->num_rows > 0){
while($row = $result->fetch_assoc() ){
echo "<tr><td>{$row['TaskSubType']}</td><td>{$row['TicketNumber']}</td><td>{$row['DateReceived']}</td><td>{$row['DateLastEdited']}</td><td>{$row['ContactLast']}</td><td>{$row['FollowupBy']}</td><td>{$row['TicketSubStatus']}</td><td>{$row['ItemType']}</td></tr>";
}
} else {
echo "0 records";
}
echo"</table>";
$conn->close();
?>
Solution
To transform the dates to the format you want, simply put
$dr= date("Y/d/m", strtotime($row['DateReceived']));
$dl= date("Y/d/m", strtotime($row['DateLastEdited']));
echo "<tr><td>{$row['TaskSubType']}</td><td>{$row['TicketNumber']}</td><td>{$dr}</td><td>{$dl}</td><td>{$row['ContactLast']}</td><td>{$row['FollowupBy']}</td><td>{$row['TicketSubStatus']}</td><td>{$row['ItemType']}</td></tr>";
Answered By - Matheus assi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.