Does PHP have a function for aggregating time values from an array? -


so query this:

select timediff('24:00:00',(timediff('22:00:00',time(end)))) time sworkingtime user='magdalena' , type='work' , start between '2014-03-01' , '2014-03-28' , (hour(`end`) > 22 or hour(`end`) < 4) , completed=1 

my query returns this:

02:02:36 03:17:24 03:07:03 02:24:17 03:14:09 

is there way modify query return sum of fields, 1 field only?

thank you

no, there's no special sum function in case - paying attention need time summation, not simple operation.

to that, can apply callback on array. powerful function array_reduce(). working date intervals can use datetime api, like:

$data = [   ['time'=>'02:02:36'],   ['time'=>'03:17:24'],   ['time'=>'03:07:03'] ];   $time = array_reduce($data, function($c, $x) {    $x = explode(':', $x['time']);    $c = explode(':', $c);    return (new datetime('2000-01-01'))       ->add(new dateinterval('pt'.(int)$c[0].'h'.(int)$c[1].'m'.(int)$c[2].'s'))       ->add(new dateinterval('pt'.(int)$x[0].'h'.(int)$x[1].'m'.(int)$x[2].'s'))       ->format('h:i:s'); }, '00:00:00'); 

-this result in "08:27:03" string. if want object, remove format() call.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -