Fatal error: Call to a member function diff() on a non-object
It seems like you're getting confused with your $to and $to1 objects. There is typo in your code. Try this on your later code:

$ot_hour =  $to1-&gt;diff($from);
$ot_minute =  $to1-&gt;diff($from);
$hour = $ot_hour-&gt;format('%h');
$minute = $ot_minute-&gt;format('%i');
$hourtominute = $hour*60;
$total = ($hourtominute+$minute)/60;
$entity_field[0]['value'] = $total;