0

Ok, I have a variable ($incubation) set as 04:00:00.
Then I have another variable ($starttime) set to the current time.
Both are printing out fine.
But I'm trying to get an $endtime from adding the incubation time to the start time.

$incubation = $row['incubation']; //IM GRABBING THIS TIME FROM THE DATABASE. It prints 04:00:00
	
	$starttime = date("H:i:s"); //prints 16:23:39
	
	$endtime = date("H:i:s", $starttime+$incubation);  //prints 20:00:00 when it's suppose to print 20:23:39
3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0

Have a look at the funktion "mktime()" on php.net. It is a very poweful yet simple function for date and time calculations.

0

Your method will work if you transform the hours into seconds. I assume your incubation is a time interval (4 hrs) as opposed to a set time (4 am).

function convTime($dbtime){
    list($h, $m, $s) = explode(':', $dbtime);
    return ($h * 3600 ) + ($m * 60 ) + $s;
}

$incubation = convTime($row['incubation']);
$starttime = date("H:i:s"); 
$endtime = date("H:i:s", $starttime+$incubation);

I got a version of this function from somewhere else some time ago. Can't remember where.

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.