₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,113 members, 8,510,215 topics. Date: Friday, 30 October 2026 at 04:00 AM

Toggle theme

Php Date Format - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Php Date Format (1271 Views)

1 Reply

Php Date Format by cs200200(op): 3:39pm On Mar 08, 2010
Hello,

I been on this simple task to most of you for some hrs now, I am currently working on a small project and I have issues with formatting my date. I will be glad if someone can help.
Problem
I have a table called tblnews and I have newsid, contentbody, newsdate. Using while statement how do I display all the news selected from my database and most importantly format the date into dd/mm/yyyy not the default yyyy-mm-dd
Re: Php Date Format by lojik(m): 5:46pm On Mar 08, 2010
$sql ="Select newsid, contentbody, DATE_FORMAT(newsdate, '%d/%m/%Y') as myNewsDate FROM tblnews";
$result = mysql_query($sql) or die("query error"wink;
while( $row = mysql_fetch_array($result) )
{
echo "newsid=".$row['newsid'];
echo "contentbody".$row['contentbody'];
echo "myNewsDate".$row['myNewsDate'];
echo "
";

}

That should solve it but i expect you to change the code inside the while loop to something more suitable.

Pleas refer to http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format for more date formats.
Re: Php Date Format by cs200200(op): 6:35pm On Mar 08, 2010
Thanks Man, the code gave me what I needed cheesy grin
1 Reply

Special Codes To Format Text On Nairaland • How To Make A Simple Calculator In Notepad Using .bat Format • How To Convert Folder/file To Jpeg Format • 2 • 3 • 4

Microsoft Office Home And Student 2010 Product Key • Please How Can I Do Self Study In Oracle • *deleted*