Page 1 of 1

Adding date() to date() unexptected ressults

Posted: Tue Sep 24, 2013 5:33 am
by Stobor
Im getting 2 date variables . One is $dowrow["FAILTIME"] (pulling it out from mysql) the other is currentlFailingLength



Code: Select all

$currentFailLength = date('H:i:s', (strtotime(date('H:i:s')) - strtotime($dowrow["LASTFAIL"])));

gives 02:53:56

$dowrow["FAILTIME"] is 00:00:04 and its TIME type in Mysql



Code: Select all

$totalFailLength = date('H:i:s', strtotime($dowrow["FAILTIME"]) + strtotime($currentFailLength));
echo $dowrow["FAILTIME"] ."+". $currentFailLength ."=". $totalFailLength;


shows 00:00:04+02:53:56=17:25:44

how to i get a proper answer in this example total should be 02:54:56 , right .... ?

Re: Adding date() to date() unexptected ressults

Posted: Tue Sep 24, 2013 5:54 am
by Celauran

Re: Adding date() to date() unexptected ressults

Posted: Tue Sep 24, 2013 6:56 am
by Stobor
Well this got me further, but i still cant make it do what i want, if i dont type something like ('1 hour') instead of ($currentFailLength) $fail remains the same

Code: Select all

$fail = $dowrow["FAILTIME"];
$fail = new DateTime($fail);
date_add($fail, date_interval_create_from_date_string($currentFailLength));
echo date_format($fail, 'H:i:s');
gettype($currentFailLength) shows that its a string but it doesnt add anything

echo $currentFailLength shows 03:42:42

will exploding and turrning it in to seconds help ? is there a better way ?

Re: Adding date() to date() unexptected ressults

Posted: Tue Sep 24, 2013 8:01 am
by Stobor

Code: Select all

list($hours,$minutes,$seconds) = explode(":", $currentFailLength);
$i = new DateInterval('PT'.$hours.'H'.$minutes.'M'.$seconds.'S');

$fail = $dowrow["FAILTIME"];
$fail = new DateTime($fail);
				
date_add($fail, $i);
fixed it somehow