I have a date in this format: Quarta, 21 Maio, 2014
.
To save this date in the database I'm converting it to datetime
as follows:
$f['data'] = $_POST['data'];
$data = DateTime::createFromFormat('l, j F, Y', $f['data']);
$data = $data->format('Y-m-d H:i:s');
Then I insert the variable $data
into my table and it works correctly. The date is saved as datetime
in the database.
But now I want to show the date, and I want to turn it back into the format Quarta, 21 Maio, 2014
.
So I'm doing my select
and then reusing DateTime::createFormat
to convert the date from datetime
to the text format I want:
$lerNoticia = $pdo->prepare("SELECT * FROM noticias WHERE");
$lerNoticia->execute();
while ($lerNoticiaResult = $lerNoticia->fetch(PDO::FETCH_ASSOC))
{
$data = DateTime::createFromFormat('l, j F, Y', $lerNoticiaResult['data']);
..... //tenho aqui mais echos a mostrar o titulo da noticia, etc
echo '<span class="data">'.$data.'</span>';
}
The problem is that the date is not appearing, what can I do wrong?