0

I'm looking to echo the date from a mysql table on a page, though it is not doing it in the format I would like. In the table the format is as follows : "06-Feb-2015" which is ideal....

Though when I grab that from the table (this is used in php):

 SELECT DISTINCT `Expiry` FROM `QA_Data`

and:

 $row = $sql->fetch();
 echo $row['Expiry'];

it echo's it out as "2015-02-06"

I''m sure this can be approached from the php or the mysql side but I would prefer the php answer if possible!

Thanks a million

Eoin
  • 357
  • 1
  • 4
  • 20
  • possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Alessandro Da Rugna Feb 06 '15 at 09:06

3 Answers3

0

You can read PHP Manual.

$date = "2015-02-06";
echo date("d-M-Y",strtotime($date));  

Output

06-Feb-2015
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
0

you can use date and strtotime functions Date Functions

$date = $row['Expiry'];
echo date("d-M-Y",strtotime($date));
Arun
  • 750
  • 5
  • 12
0

Yon can convert the date to a string in mySQL:

SELECT DISTINCT DATE_FORMAT(`Expiry` , '%d-%b-%Y') AS Expiry;

and:

$row = $sql->fetch();
echo $row['Expiry'];

From: date_format function manual

But if you prefer php side:

$row = $sql->fetch();
echo date("d-M-Y", strtotime($row['Expiry']));
kiks73
  • 3,718
  • 3
  • 25
  • 52