2
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 insert the variable $data
in my table and 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 mine select
and then to use the DateTime::createFormat
to convert the date of datetime
for 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 date’s not showing up, which I might be doing wrong?
Thank you William for the answer, I expressed with your function and it worked. But I was really trying with datetime! However with the help of user692 I have already succeeded in doing this. Thank you!
– Mib