Level 73
Why don't you use Carbon?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
<?php
$date = date_create($add->created_at);
$dateFr = date_format($date,"d/m/Y H:i:s");
$new_time = date($dateFr, strtotime('+2 hours'));
echo $new_time; // does not output the hour with +2 hours
?>
The first parameter of the date() function is the date format (e.g. 'Y-m-d'), but you're passing a formatted date string instead.
Here's one way to do it using strtotime():
$datetime = date_create($add->created_at);
$new_time = date('d/m/Y H:i:s', strtotime($datetime->format('c').' +2 hours'));
But since you're using a DateTime object, you can just do this:
$new_time = date_create($add->created_at)->modify('+2 hours')->format('d/m/Y H:i:s');
Please or to participate in this conversation.