I have a query to get date_created from the database
$stmt = $con->prepare('SELECT `id`, `title`, `main_image`, `services`, `date_created` FROM `news` ORDER BY `id` DESC');
$stmt->execute();
$stmt->bind_result($id, $title, $main_image, $services, $date_created);
while ($stmt->fetch()) {
$news[] = ['id' => $id, 'title' => $title, 'main_image' => $main_image, 'services' => $services, 'date_created' => $date_created];
}
When I want to show date_created in HTML with the format d/m/Y H:i
foreach ($news as $new) {
date_format($new['date_created'], "d/m/Y H:i")
}
Get error Warning: date_format() expects parameter 1 to be DateTimeInterface, string given in
$new['date_created']into aDateTimeobject. - Barmardate_format(date_create($new['date_created']), "d/m/Y H:i")- tttony