I have a small issue while calculating sum of total hours Show My working hours is like:
How can I get it by php? Thanks in advance
Noich 13.7k15 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,7404 gold badges26 silver badges39 bronze badges answered Mar 13, 2013 at 12:06
Bart FriederichsBart Friederichs 32.3k15 gold badges96 silver badges187 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
View Discussion Improve Article Save Article View Discussion Improve Article Save Article Given an array containing the time in hr:min:sec format. The task is to calculate the total time. If the total time is greater then 24 hours then
the total time will not start with 0. It will display the total time. There are two ways to calculate the total time from the array.
Using strtotime() function: The strtotime() function is used to convert string into the time format. This functions returns the time
in h:m:s format. strtotime( string ) Example 1: This example reads the values from the array and converts it into the time format. php
Using explode() function: The explode() function is used to break a string into an array. array explode( separator, string, limit ) Example 2: This example reads the values from an array and converts it into the time
format. php
How do I calculate total hours in PHP?There are two ways to calculate the total time from the array. Using strtotime() function: The strtotime() function is used to convert string into the time format. This functions returns the time in h:m:s format.
How can I calculate hours between two dates in PHP?$hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1); Dividing by 3600 because there are 3600 seconds in one hour and using round() to avoid having a lot of decimal places.
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); ?>
How is start time and end time calculated in PHP?“calculate total time from start and end datetime in php” Code Answer. date1 = new DateTime('2006-04-12T12:30:00');. $date2 = new DateTime('2006-04-14T11:30:00');. $diff = $date2->diff($date1);. $hours = $diff->h;. $hours = $hours + ($diff->days*24);. |