Jump to content

how to display date in dd-mm-yyyy


vivification

Recommended Posts

Hi there,

 

I am still new to PHP and having trouble trying to format a date.

 

When the form data is saved; it is saved as YYYY-MM-DD.

 

Then, when you view a page to display all the records, it shows as YYYY-MM-DD.

I want to convert it to show DD-MM-YYYY.

 

The field name is "ETD" and "ETA".

 

Can I just use:

echo date("Y/m/d") ?

If so, how do I use it in the below scenario.

 

Would it be:

 

echo "<td>" . $row['etd']date("Y/m/d") . "</td>"; 

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href='edit--report.php?id=" . $row['ID'] . "' >" . $row['ID'] . "</a></td>";
  echo "<td>" . $row['etd'] . "</td>";         
  echo "<td>" . $row['eta'] . "</td>";
  echo "</tr>";
  }
echo "</table>";


//mysqli_close($con);
?>

Would appreciate any help!

 

Thanks,

Link to comment
https://forums.phpfreaks.com/topic/284633-how-to-display-date-in-dd-mm-yyyy/
Share on other sites

Thanks hitman, but can you show me how I enter it on my code?

 

I dont understand how I need to enter/display it in my code.

Are they both on the same line? 

 

i.e.

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><a href='edit--report.php?id=" . $row['ID'] . "' >" . $row['ID'] . "</a></td>";
  echo "<td>" . $date = new DateTime($row['etd']);
print $date->format('d-m-Y') "</td>";         
  echo "</tr>";
  }
echo "</table>";

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.