Jump to content

Display Date From MySql DB


Kerry_7777

Recommended Posts

I have been building a webpage to display upcoming events. The date is displayed on the page as year/month/day. Arggghhh!!! I need to reverse the format. Have tried lots of things but cant get it to work. Also I want to display the highest dates in the table but put the events in normal upcoming order. Please see my code below:

<?php

require_once '******.inc.php';

  $query = 'select date, name, time, venue, info from tbl***** order by date DESC LIMIT 0,5';

  $result = mysql_query($query);

 

  if (!$result)

  {

exit("Error retrieving courses from database");

}

if (mysql_num_rows($result) <1)

{

exit("No courses records found ");

}

  ?>           

<table>

<tr>

<th>Name</th>

<th>Date</th>

        <th>Time</th>

    <th>Venue</th>

    <th>Information</th>

</tr>

 

  <?php

while ($row = mysql_fetch_array($result))

{

$Name = $row['name'];

 

$Date = $row['date'];  #WHAT DO I DO HERE?

 

$Time = $row['time'];

$Venue = $row['venue'];

$Info = $row['info'];

  ?>

<tr>

    <td><p><?= $Name; ?></p></td>

<td><p><?= $Date; ?></p></td>

<td><p><?= $Time; ?></p></td>

        <td><p><?= $Venue; ?></p></td>

        <td><p ><?= $Info; ?></p></td>

</tr>

  <?php } ?>

  </table>

Link to comment
https://forums.phpfreaks.com/topic/177369-display-date-from-mysql-db/
Share on other sites

first of all use php tags it makes it much easier to read.

 

if your date column is a datetime value you could do this

     $query = 'select date_format(date,'%d/%m/%Y') as date, name, time, venue, info from tbl***** order by date DESC LIMIT 0,5';

or in php

$formatted_date=date("d/m/Y", strtotime($row['date'])); 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.