Forum Moderators: coopster
$start=mktime (10,30,0,1,1,03);
$end=mktime (10,45,0,1,1,03);
$result=$end - $start;
echo "<p> ". date("G:i", $start). " to ". date("G:i", $end). " Total Worked - ". date("G:i", $result). " hours</p>";
On my local machine it works fine i get:
10:30 to 10:45 Total Worked - 0:15 hours
but as soon as I upload it to another server i get :
10:30 to 10:45 Total Worked - 1:15 hours
Since I'm making a false time it should'nt make any difference where its hosted. right?
right. That is very strange, you have the same code working on another machine and the logic looks sound (though I just got up so who knows).
but
I tried it on one of my servers and got this
10:30 to 10:45 Total Worked - 19:15 hours
obviously the logic is somehow skewed. hmmmm.
$start=mktime (10,30,0,1,1,03);
$end=mktime (10,45,0,1,1,03);
$result=$end - $start;
$dhour = $result/3600; // to get hours
$diff = split ('[.]', $dhour);
echo "<p> ". date("G:i", $start). " to ". date("G:i", $end);
echo "<br>Total Worked is " . $diff[0] . " hours and " . ($diff[1]/100)*60 . " minutes.";
<added>the logic, I figured, is that we just need the difference between the two, which we get in seconds. From there you can do the math by hand instead of trying to get the date() function to do it. Especially since the date() function doesn't seem to be up to it.
That works fine although I had to tweak the code to get 30 mins to appear - otherwise you just get a 3.
Still not sure why I get the results I do the other way.
Since I'm going to be storing $start and $end and wanting to calculate totals over weeks and months maybe I would be better off not using mktime at all and just converting basic numbers like 10:30 to seconds and minutes?
$x=mktime (0,10,1,1,1,03);
$y=mktime (0,10,1,1,1,03);
$z=mktime (0,10,1,1,1,03);
$xyz=$x + $y;
$xyz=date("G:i", $xyz);
echo "total = $xyz";
just adding x + Y give the correct answer of 20 mins BUT throw in Z and it all goes pear shaped
why? I have searched everywhere trying to find an answer...someone please tell me why *sob* *sob*