I need a PHP function to calculate time periods

Can someone can help me to create a php function that calculates time between two dates excluding break, lunches, and weekends

function timeinqueue()
{
}

I do not think it works like that @eliasskate_8 you have to put a bit more effort in than you have posted. You should be able to calculate the time between two dates removing the breaks and lunches. Start with that and you can come back and ask about how to work in the weekend part…

3 Likes
function timeinqueue($startDate, $endDate)
{
}

Your go.

2 Likes

yeha i know ho to calculated time between two but here is my problem I have a basic knowledge of programming i create a scanning system when a work order is scanning type in in a certain location is my $start time and when they scanning type out is my $end that gives me a time between those day and just by extract the breaks but what about if they scan type in a work order Friday at 4:30 and scan type out Monday at 8:00 it will count Saturday and Sunday.

here what i got so far.

function timequeue($start, $end)
{
$ptime = $start->diff($end);
$output = $ptime->format(' %d Days, %h Hours : %i Minutes');

echo $output;

}

i get to this point but Saturdays and Sundays won’t work

Could you provide a well formatted code? The way you posted it contains some serious syntax errors. Some example and expected output would make it easier for your helpers to get into the topic.

Does this older thread provide any useful ideas? Calculate the number of working day hours between two dates - #4 by Drummin

Thanks guy for the help i made it work

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.