datetime - How to calculate the time consumed from start time to end time in php -
i want perfect time consumed or total time start time end time:
code:
$start_time = $this->input->post('start_time'); $end_time = $this->input->post('end_time'); $t1 = strtotime($start_time); $t2 = strtotime($end_time); $differenceinseconds = $t2 - $t1; $differenceinhours = $differenceinseconds / 3600; if($differenceinhours<0) { $differenceinhours += 24; } in code above if $start_time = 11:00:00 pm , $end_date =11:30:00 gives me output of 0.5 instead of 30minutes. there appropriate way that?
if the:
$start_time = '01:00:00 pm'; $end_time = '01:25:00 pm'; $total = '25:00'; // 25 minutes or:
$start_time = '11:00:00 pm'; $end_time = '11:00:25 pm'; $total = '00:00:25'; // 25seconds regards!
try diff function
<?php echo date_create('03:00:00 pm')->diff(date_create('03:25:00 pm'))->format('%h:%i:%s'); ?> output
00:25:00
Comments
Post a Comment