0

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.

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by baseballfury
0

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'";

Edited by urtrivedi: n/a

0

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.

0

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

0

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']));
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.