i am trying to calculate my working hours.

I have a start time, a finish time and a lunch flag.

What i am hoping to achieve is:

difference between start & End time.
If Lunch flag equals yes then deduct an hour from the Total.

Can anyone help?

Thanks in advance

This is an extremely simple way of doing it, but I think it works for the purpose.

<?
$lunchflag = false; //true if lunch taken

$datebegin = mktime(8, 00, 00, 10, 01, 2008); //timestamp for 8:00 10/1/2008
$dateend = mktime(17, 12, 00, 10, 01, 2008); //timestamp for 5:12 10/1/2008

echo "date 1:" . $datebegin . "<br />";
echo "date 2:" . $dateend . "<br />";

$diff = $dateend - $datebegin;

$hours = floor($diff / (60 * 60));
$minutes = ($diff % (60 * 60)) / 60; //for nice round minutes you can round(), floor() or ceil()

$hours = $lunchflag?$hours - 1:$hours;

echo $hours . ":" . $minutes;
?>

How can i use the time from mysql fields using this format: 00:00:00 ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.