0

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;

?>
2
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by ramsiva
0

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

1

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
)

Edited by cereal

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.