-1

I'm having some issues converting yyyy-mm-dd to text, and could use some pointers. This is what I currently have, but this obviously just outputs the numerical date:

$insert_date = $row['INSERT_DATE'];
$line_text = $row['LINE_TEXT'];
echo  "<tr height='10'><td>".$insert_date."</td>";

I'm unsure whether I should use the strtotime or date functions?

In other words, dates are in the MySQL DB as numerical entries, in the format, yyyy-mm-dd. Currently, the outputs matches this (eg, 2007-02-14). I'd prefer this to appear as February 14, 2007.

Thanks in advance.

R14
  • 152
  • 1
  • 10

1 Answers1

3

You can use the format method of the DateTime class:

$date = new DateTime('2000-01-01');
$result = $date->format('Y-m-d H:i:s');

If format fails for some reason, it will return FALSE. In some applications, it might make sense to handle the failing case:

if ($result) {
  echo $result;
} else { // format failed
  echo "Unknown Time";
}
1w3j
  • 566
  • 8
  • 24