I am not getting the totalapps any body help me

 <?php  $event_time = "9:30 am";
         $end_time="11:00 am";
         $event_length = 4;
     $dtime_1 = new Datetime($event_time);
$dtime_2 = new Datetime($end_time);
$diff = $dtime_1->diff($dtime_2);
$hourone=$diff->format('%H');
$minuteone=$diff->format('%I');
$hourtotalmin=$hourone*60;
$totalmin=$minuteone+$hourtotalmin;
$totalapps=$totalmin/$event_length;
echo $totalapps;

?>

Recommended Answers

All 3 Replies

when i tried with $totalapps=round($totalmin/$event_length);
floor and ceil also i am getting NAN Error

Hi, it seems fine to me, but you can use directly the object created by the diff() method, without formatting the output, as in my previous example:

$minutes  = 0;
$minutes += $diff->h * 60;
$minutes += $diff->i;

echo round($minutes / 4);

Which outputs 23, with floor 22. If you do print_r($diff) you will see:

DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 1
    [i] => 30
    [s] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 0
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Very Thanks
problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.