Counting every minute instead of hours

Hi there,

I have a php script where i am putting all work hours into the database.
Now when i click work time start at 01:00 till 01:15 it shows 0 hours of work time
When i click work time 01:00 till 02:00 it shows 1 hour, that is good tho.

But i wanna have the result for example 1:15 hour.

This is my script:

    $datum = date("d-m-Y",strtotime($start));
				$startTijd = date("H:i",strtotime($start));
				$eindTijd = date("H:i",strtotime($eind));

				$totaal = $eindTijd - $startTijd;

				$urenTotaal += $totaal;

<td width="100"><?=number_format($totaal, 2, ',', '.')?> uur</td>

<th colspan="4"><?=number_format($urenTotaal, 2, ',', '.')?> uur</th>

The times he will get from the database

$startTijd and $eindTijd are strings. You cannot do date/time math on strings (the ‘:’ character is a stop character and php is just subtracting the numbers before the ‘:’.)

Doing this properly takes some planning. For example, if a time period can span midnight or be longer than 24 hours, you must do this using the full date and time of both the start and end values.

While php’s date/time functions can calculate a time interval, if you add these, once you have more than 24 hours, you get a datetime value relative to the starting date you used. Doing this in MySql is better, because you can do time math that adds up to 838 hours.

A universal solution would be to just convert the values to Unix Timestamps (seconds), do the subtraction and any total accumulation, then convert the results back to hours, minutes, seconds.

Sponsor our Newsletter | Privacy Policy | Terms of Service