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
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'])); 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.