Hello,

I'm returning results from a database but they are showing as yyyy/mm/dd
I would like them to display as dd/mm/yyyy is there a simple way to format $newrow5 to do this.

while ($newrow5 = mysql_fetch_array($result5))
{
echo "Starts on the: {$newrow5}";
}

thanks in advance,

Tom.

use date_format() function in your sql query

$query="select date_format(startdate, '%d/%m/%Y') as startdate, col1,col2,col2 from mytable where col1='mycondition'";

explode your date and print as per your need.

I've tried editing my query as per you instructions and ended up with the following:

$sql4 ="SELECT Company.Link, Company.Address, Company.TelOther, Company.HomeTel, Company.Area, Company.Classification, Company.Class2, Company.Class3, Promotions.CompanyName, Promotions.PName, Promotions.PDescription, Promotions.Monday, Promotions.Tuesday, Promotions.Wednesday, Promotions.Thursday, Promotions.Friday, Promotions.Saturday, Promotions.Sunday, date_format(Promotions.StartDate, '%d/%m/%Y'), Promotions.EndDate, Promotions.PromoID
FROM Company INNER JOIN Promotions
ON Company.Name=Promotions.CompanyName WHERE Promotions.EndDate IS NULL AND '".$q."' >= Promotions.StartDate AND Company.Classification = '".$p."' ORDER BY Promotions.StartDate ASC";

It's now showing an unexpected T-Variable error.

Any thoughts?

Cheers.

I've tried editing my query as per you instructions and ended up with the following:

$sql4 ="SELECT Company.Link, Company.Address, Company.TelOther, Company.HomeTel, Company.Area, Company.Classification, Company.Class2, Company.Class3, Promotions.CompanyName, Promotions.PName, Promotions.PDescription, Promotions.Monday, Promotions.Tuesday, Promotions.Wednesday, Promotions.Thursday, Promotions.Friday, Promotions.Saturday, Promotions.Sunday, date_format(Promotions.StartDate, '%d/%m/%Y'), Promotions.EndDate, Promotions.PromoID
FROM Company INNER JOIN Promotions
ON Company.Name=Promotions.CompanyName WHERE Promotions.EndDate IS NULL AND '".$q."' >= Promotions.StartDate AND Company.Classification = '".$p."' ORDER BY Promotions.StartDate ASC";

It's now showing an unexpected T-Variable error.

Any thoughts?

Cheers.

in the php for the output, not the sql query, sql requires only column names

first of convert the fetched value in timestamps then display it according to your need.

while ($newrow5 = mysql_fetch_array($result5))
{
 echo  date('d/m/Y',strtotime($newrow5['StartDate']));
}

thanks mate, much appreciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.