/    Sign up×
Community /Pin to ProfileBookmark

Counting total business hours affected

Hello,

I have two datetime stamps I need to determine the business hours affected during these two datetime stamps.

I’m working along the lines of the following:

[code=php]
function calcBusiness($stime,$ftime){

$stime = explode(‘ ‘,$stime);
$ftime = explode(‘ ‘,$ftime);

if($stime[0] > $ftime[0])
{

if($stime[1] <= ’04:00:00′){
if($ftime[1] >= ’20:00:00′){
$stimeMIN = strtotime($stime[1]);
$ftimeMIN = strtotime($ftime[1]);
$diffMIN = round(abs($ftimeMIN – $stimeMIN) / 60,2);
}
}

}else{
echo “00:00:00”;
}

if($stime[0] == $ftime[0]

return $totalBusinessHours;
}
[/code]

I’ve hit a bit of a cross road here.
HELP?!?!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ericatekkaauthorJul 18.2011 — [code=php]
function calcBusiness($stime,$ftime){

$stime = explode(' ',$stime);
$ftime = explode(' ',$ftime);

if($stime[0] < $ftime[0])
{

if(strtotime($stime[1]) > strtotime('04:00:00')){
$stimeMIN = strtotime($stime[1]);
$stimeone = strtotime('20:00:00');
$totalFirst = $stimeone - $stimeMIN;
}else{
$totalFirst = 57600;
}

if(strtotime($ftime[1]) < strtotime('20:00:00')){
$ftimeMIN = strtotime($ftime[1]);
$ftimeone = strtotime('04:00:00');
$totalLast = $ftimeMIN - $ftimeone;
}else{
$totalLast = 57600;
}

if(!empty($totalFirst) & !empty($totalLast)){
$diffMIN = ($totalFirst + $totalLast) / 60;
//echo $diffMIN."|";
}



if(strtotime($stime[0]) == strtotime($ftime[0]) || (strtotime($stime[0]) + 86400) == strtotime($ftime[0])){
//echo "<br />START ".strtotime($stime[0]);
//echo "<br />END ".strtotime($ftime[0]);
//echo "<br />ALT END".(strtotime($stime[0])+86400);
$diffTimeMIN = 0;

}else{
$bizSecs = 57600;
$days = ((strtotime($ftime[0]) - (strtotime($stime[0])+86400)) / (60 * 60 * 24));
$totSecs = $bizSecs * $days;
$diffTimeMIN = $totSecs / 60;
}

}elseif($stime[0] = $ftime[0]){
$ftimeMIN = strtotime($ftime[1]);
$ftimeone = strtotime($stime[1]);
$totalLast = $ftimeMIN - $ftimeone;
$diffMIN = $totalLast / 60;
$diffTimeMIN = 0;
}else{
$diffMIN = 0;
$diffTimeMIN = 0;
}

$totalBusinessHours = $diffMIN + $diffTimeMIN;

return $totalBusinessHours;
}

function minutesToHours($minutes)
{
$hours = (int)($minutes / 60);
$minutes -= $hours * 60;
$minutes = (strlen($minutes) > 1)?$minutes:"0".$minutes;
$hours = (strlen($hours) > 1)?$hours:"0".$hours;
$time = $hours.":".$minutes.":00";
return $time;
}
CALL: minutesToHours(calcBusiness($x['start'],$x['end']))
[/code]


FYI
×

Success!

Help @ericatekka spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...