I want to get the perfect time consumed or the total time from start time to end time:
My 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 the code above if $start_time
= 11:00:00 PM
and $end_date =11:30:00
it gives me the output of 0.5
instead of 30minutes
. Is there any appropriate way to do it like that?
So 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 using diff:
You can use strtotime() for time calculation. Here is an example:
Output:
Try diff function
Output
You have to check everything using if and else statement. I think this one help.