/    Sign up×
Community /Pin to ProfileBookmark

Adding date variable to date varriable

Im getting 2 date variables . One is $dowrow[“FAILTIME”] (pulling it out from mysql) the other is currentlFailingLength

[CODE]
$currentFailLength = date(‘H:i:s’, (strtotime(date(‘H:i:s’)) – strtotime($dowrow[“LASTFAIL”]))); [/CODE]

gives 02:53:56

$dowrow[“FAILTIME”] is 00:00:04

[CODE]$totalFailLength = date(‘H:i:s’, strtotime($dowrow[“FAILTIME”]) + strtotime($currentFailLength));
echo $dowrow[“FAILTIME”] .”+”. $currentFailLength .”=”. $totalFailLength; [/CODE]

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 …. ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NoEffinWaySep 24.2013 — An important thing to remember: strtotime make a time stamp for the entire YEAR. so you are adding two full dates. Here, I suck at explaining things but here is a script with the full break down, maybe it will help you understand.
[code=php]
<?php

$dowrow["FAILTIME"] = '00:00:04';
$currentFailLength = '02:53:56';

$s1 = strtotime($dowrow["FAILTIME"]);
$s2 = strtotime($currentFailLength);

$totalFailLength = date('H:i:s', (strtotime($dowrow["FAILTIME"]) + strtotime($currentFailLength)));
echo "Stamp 1: {$s1}nStamp 2: {$s2}nn";
echo "Stamp 1 + Stamp 2 = " . ($s1+$s2) . "nn";
echo "Stamp 1 [Ymd His]: " . date("Y-m-d H:i:s", $s1) . "nStamp 2 [Ymd His]: " . date("Y-m-d H:i:s") . "nn";
echo "Added Stamps [Ymd His]: " . date("Y-m-d H:i:s", ($s1+$s2)) . "nn";
echo $dowrow["FAILTIME"] ." + ". $currentFailLength ." = ". $totalFailLength . "nn";

/*WHAT YOU NEED IS BELOW THIS LINE*/

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

echo "The result you want: {$correctWay}";

?>
[/code]
Copy linkTweet thisAlerts:
@StoborauthorSep 24.2013 — Thanks [B]NoEffinWay[/B] but your option didnt work, fixed it myself though


[CODE]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);

echo date_format($fail, 'H:i:s');[/CODE]
Copy linkTweet thisAlerts:
@NoEffinWaySep 24.2013 — Yeah, I realized now that the time is wrong. I shouldn't be awake this early. Anyway, glad you figured it out, good luck!
×

Success!

Help @Stobor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...