我有一個查詢在html頁面中顯示即將到來的日期。我試圖讓日期顯示爲dd/mm/yyyy。完整的代碼如下。 「date1」是我想要顯示的日期。在php中更改日期的格式
<?php
$con=mysqli_connect("localhost","root","","mentertraining");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT `coursedates`.`coursedate_id`,`courses`.`course_title`,`courses`.`no_of_days`,`category`.`category_name`,`coursedates`.`date1` FROM coursedates "
. " LEFT JOIN `mentertraining`.`courses` ON `coursedates`.`course_id` = `courses`.`course_id` "
. " LEFT JOIN `mentertraining`.`category` ON `courses`.`category_id` = `category`.`category_id` LIMIT 0, 5 ";
$result = mysqli_query($con,$query);
echo "<table cellspacing='1'><tr bgcolor='#fe0075'><th>Course Title</th><th>Course Date</th></tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['course_title'] . "</td>";
echo "<td>" . $row['date1'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
感謝所有幫助
完善三江源 – user2536134