Two dates get hour and minute using PHP

Today, we’ll discuss how to calculate date and time difference in PHP. The easiest way to calculate the time difference in PHP is using diff function().

Code

$current_date = date('Y-m-d H:i');
$datebase_date = date('2018-03-09 08:40');
$datetime1 = new DateTime($current_date);
$datetime2 = new DateTime($datebase_date);
$interval = $datetime1->diff($datetime2);
echo $interval->format('%h')." Hours ".$interval->format('%i')." Minutes";

Leave a Reply

Your email address will not be published. Required fields are marked *