1

I have trouble in converting this date. What I want is to convert the date formated in yyyy-mm-dd into Month day year. How can I achieve this? below is my code.

$news = mysql_query("SELECT * FROM tblupcomingevents WHERE date >= CURRENT_DATE() LIMIT 5") or die(mysql_error());
while($row = mysql_fetch_array($news))
{?>
<?php echo $row ["date"] ?>
<?php echo $row ["place"] ?>
<?php
}
?>
Kevin
  • 41,694
  • 12
  • 53
  • 70
Danilo Escapa
  • 141
  • 1
  • 2
  • 10

4 Answers4

15

Use the PHP date function to reformat it:

echo date('F j, Y',strtotime($row['date']));  // January 30, 2015, for example.

See date for many more formatting options.

3

Primary objective is to convert your date string (in the format of 'yyyy-mm-dd') into timestamp. Timestamp makes it easier / possible for php to convert it into one of many formats that you may desire.

For instance, you want 2015-01-30 to be listed as January 30, 2015, all you need to do is:

<?php
$timestamp = strtotime("2015-01-30");
$formattedDate = date('F d, Y', $timestamp);
echo $formattedDate;
?>

You can, however, choose other formats for your presentation from: http://php.net/manual/en/function.date.php

Hope it helps!

2

You can use strtotime()

$date=date('m-d-Y',strtotime($row["date"]));

Output would look like this:

01-01-2000

You can refer here for more date format and change the value inside the code I have given.

Logan Wayne
  • 6,001
  • 16
  • 31
  • 49
1

In MySQL, you can use date_format():

select date_format(datecol, '%M %d %Y)

The complete documentation for the function is here. It provides a lot of flexibility in the output string format for a date.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786