PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Mod | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
ok so heres what im doing now... sorry i post with so much help needed.. i just suck
ne way im making a clock in system and i have everything good except for one thing.. thats right i am having problems with total times
so lets say i clocked in at
1:05:00 pm
and clocked out at
2:00:00 pm
so i worked for 55 mins
the system i made for it isnt complete cause it would just parse out
-5 Min instead of 55 M ... here is my code
<?php
///////////// It runs out of my database --- So i use explodes and i use 24 hour times
$explodeS = explode(":", $row['fullTimeS']);
$explodeF = explode(":", $row['fullTimeF']);
if($explodeF[0] - $explodeS[0]==0){
$first = "";
}else{
$first = $explodeF[0] - $explodeS[0]."<b>H</b> ";
}
if($explodeF[1] - $explodeS[1]==0){
$second = "";
}else{
$second = $explodeF[1] - $explodeS[1]."<b>M</b> ";
}
if($explodeF[2] - $explodeS[2]==0){
$third = "";
}else{
$third = $explodeF[2] - $explodeS[2]."<b>S</b> ";
}
echo $first.$second.$third;
?>
Mod | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too.
<?php
// Work out the differene between start and finish in seconds
$totaltime_seconds = strtotime ($row['fullTimeF']) - strtotime ($row['fullTimeS']);
// Display the total time in HH:MM:SS format
$totaltime_formatted = date ("H:i:s", $totaltime_seconds-3600);
?>
The reason I do -3600 (-1 hour) on line 7 was to make the answer correct on my machine. This may be different on yours.
and i used the code you posted instead of my code (BUT CHANGED IT A LITTLE FROM [ $totaltime_seconds = strtotime ($row['fullTimeF']) - strtotime ($row['fullTimeS']); ] TO [ $totaltime_seconds = strtotime ($row['fullTimeS]) - strtotime ($row['fullTimeF']); ] ) and i get this
fullTimeS (starting time) - 09:41:57
fullTimeF (finish time) - 10:03:45
came out to Total Time = 14:38:12
i will try to come up with a way to get urs to work with mine but if you can help me more than that would be great!
thanks
You should really store the time as either a MySQL date stamp (which will allow you to use MySQL's date functions to figure this out), or a UNIX timestamp, which will let you use PHP & simple math to figure it out. Proprietary date formats are almost never a good idea.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
# // Work out the differene between start and finish in seconds
$totaltime_seconds = strtotime ($row['fullTimeF']) - strtotime ($row['fullTimeS']);
#
# // Display the total time in HH:MM:SS format
$totaltime_formatted = date ("H:i:s", $totaltime_seconds-3600);
echo $totaltime_formatted;
The echo equals this:
fullTimeS = 8:00:11
fullTimeF = 8:10:34
Total = 15:10:23
So what i can see is it is setting 15 as 0 so this is my full code for display
what id did was added up the hours (3600) to make the basis time not be 15 and came up with -57600 instead of -3600 and now i have the right hours displayed!
Thank you guys so much for all your help!
Last edited by ccrevling on Wed Mar 05, 2008 11:37 am, edited 1 time in total.