I have a small issue while calculating sum of total hours Show Nội dung chính
My working hours is like:
How can I get it by php? Thanks in advance Noich 13.6k15 gold badges61 silver badges90 bronze badges asked Mar 13, 2013 at 12:02 0 Just add them like this:
It is quite elaborate like this, but it just to show the idea: calculate back to minutes, add minutes together, then calculate back to hours. Note that PHP has quite extensive support for dates and times. Consider using that: http://www.php.net/manual/en/book.datetime.php admdrew 3,7254 gold badges25 silver badges39 bronze badges answered Mar 13, 2013 at 12:06 Bart FriederichsBart Friederichs 32.2k15 gold badges96 silver badges186 bronze badges This technique will give exact total hours and minutes. The above answer gives me 1.25.15 when i add 00:30 and 00:45
answered Feb 2, 2018 at 11:46 Vishnu BhadoriyaVishnu Bhadoriya 1,6161 gold badge21 silver badges28 bronze badges If you use this function to calculate time calculation then it will work
For more explanation refer this link: Time Calculation in php answered Mar 13, 2013 at 12:16 by Vincy. Last modified on July 11th, 2022. In PHP, there are many ways to calculate the difference between two dates. In this tutorial, we are using PHP date time functions to calculate the hour difference between two dates. In this example, we are start and end dates from the user. And then, we use strtotime() to convert the date string into timestamp to calculate the difference. View Demo HTML Datetime InputThis code shows the input field to get the start and end date from the user.
PHP Function to Calculate Hours DifferenceWe call this PHP function when the user submitting the date ranges to calculate the hour difference.
View DemoDownload ↑ Back to Top How do you calculate the number of hours?How to calculate hours worked. Determine the start and the end time. ... . Convert the time to military time (24 hours) ... . Transform the minutes in decimals. ... . Subtract the start time from the end time. ... . Subtract the unpaid time taken for breaks.. How can I calculate hours between two dates in php?You can convert them to timestamps and go from there: $hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1); How do you total in php?Begin calculating the total cost: $total = $price * $quantity; $total = $total + $shipping; $total = $total - $discount; The asterisk (*) indicates multiplication in PHP, so the total is first calculated as the number of items purchased ($quantity) multiplied by the price. How can I add hours and minutes in php?php function CalculateTime($times) { $i = 0; foreach ($times as $time) { sscanf($time, '%d:%d', $hour, $min); $i += $hour * 60 + $min; } if($h = floor($i / 60)) { $i %= 60; } return sprintf('%02d:%02d', $h, $i); } $date[] = '02:32'; $date[] = '01:29'; echo CalculateTime($date); ?> |