₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,229 members, 8,420,899 topics. Date: Friday, 05 June 2026 at 01:45 PM

Toggle theme

Php Date Format - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPhp Date Format (1239 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 NairalandHow To Make A Simple Calculator In Notepad Using .bat FormatHow To Convert Folder/file To Jpeg Format234

A Nairalander's Mobile App For Naija Online Radio Station(Tijanja Radio 2.0)Spectranet For Linux강남매직미러《o1o 9742 1199》♬김사랑실장 강남매직미러초이스 선릉매직미러초이스 역삼매직미러초이스 강남풀사롱가격 강남풀살롱견적 강남풀사롱예