I want to calculate the time from two dates, which date value get from the database. I have retrieved the data from the database apply this code:
foreach ($selectData as $data) { echo $data["check_in"]; echo $data["check_out"]; }
My date formate: Y-m-d H:m:s
But not calculate the total munites from tow date. How can I calculate the time between two dates using PHP?
Apply this code to calculate the time between two dates in PHP
<?php $to_time = strtotime("2019-08-20 10-30-35"); $from_time = strtotime("2019-08-20 19-30-15"); $total_time += round(abs($to_time - $from_time) / 60,2). " minute"; echo $total_time; ?>
For example:
<?php $total_time=0; foreach ($selectData as $data) { $to_time = strtotime($data["check_in"]); $from_time = strtotime($data["check_out"]); $total_time += round(abs($to_time - $from_time) / 60,2). " minute"; } echo $total_time; ?>
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io