How to calculate the hour,min between two date time?

cakephp, php

Solution

Make use of `DateTime::diff` of the `DateTime` Class

<?php
$datetime1 = new DateTime('2014-02-11 04:04:26 AM');
$datetime2 = new DateTime('2014-02-11 05:36:56 AM');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%h')." Hours ".$interval->format('%i')." Minutes";

`OUTPUT :`

1 Hours 32 Minutes

Problem

I have two date's ``` $date1 = "2014-02-11 04:04:26 AM" $date2 = "2014-02-11 05:36:56 AM" ``` I want to calculate the difference and display it as follows `1 hour 32 minutes`

Original source

Related problems