Datumsdifferenz geht nicht richtig?

PHP:
$return = array();
$difference = $time_b - $time_a;
$return['days'] = floor($difference / (60 * 60 * 24));
$difference -= $return['days'] * (60 * 60 * 24);
$return['hours'] = floor($difference / (60 * 60));
$difference -= $return['hours'] * (60 * 60);
$return['minutes'] = floor($difference / 60);
$difference -= $return['minutes'] * 60;
$return['seconds'] = $difference / 60;
return $return;
 
Zuletzt bearbeitet:
Aber dann würde ich einfach -= nehmen. Das %= ist mir suspekt, obwohl ich das von C kenne.
modulus - Returns the remainder obtained by dividing the first argument by the second argument

Axo... du meinst den Rest beim Dividieren...
 
Zuletzt bearbeitet:
Original geschrieben von won_gak
PHP:
$return = array();
$difference = $time_b - $time_a;
$return['days'] = floor($difference / (60 * 60 * 24));
$difference -= $return['days'] * (60 * 60 * 24);
$return['hours'] = floor($difference / (60 * 60));
$difference -= $return['hours'] * (60 * 60);
$return['minutes'] = floor($difference / 60);
$difference -= $return['minutes'] * 60;
$return['seconds'] = $difference / 60;
return $return;
Das Ergebnis ist erschreckend :(
PHP:
<?php

function diff($b_time){
$now = mktime();
$time_a = mktime(20,0,0,date("n",$now),date("j",$now),date("Y",$now));
$return = array();
$difference = $time_b - $time_a;
$return['days'] = floor($difference / (60 * 60 * 24));
$difference %= $return['days'] * (60 * 60 * 24);
$return['hours'] = floor($difference / (60 * 60));
$difference %= $return['hours'] * (60 * 60);
$return['minutes'] = floor($difference / 60);
$difference %= $return['minutes'] * 60;
$return['seconds'] = $difference / 60;
return $return;

}

$zeit = mktime() + "3600";
$noch = diff($zeit);

if($noch["days"]!=""){
echo $noch["days"]."T ";
}
if($noch["hours"]!=""){
echo $noch["hours"]."Std ";
}
if($noch["minutes"]!=""){
if($noch["days"]=="" && $noch["hours"]==""){
echo "<span class=\"red\">".$noch["minutes"]."Min</span>";
}
else {
echo $noch["minutes"]."Min";
}
}

?>
-12290T -294954Std :(
 
Sorry, ich hatte da noch das falsche drin.

-= statt %=

Ich bin auch verwirrt. Der bekannte Zeitpunkt (20 Uhr) ist doch immer beim END-Zeitpunkt, und nicht beim aktuellen timestamp? Du hast aber bei mktime () 20 stehen bei den Stunden... das kann logisch nicht ganz gehen.
 
Zuletzt bearbeitet:
Führt bei mir zu ähnlich schrecklichen Ergbenissen...
Nur die Stunden werden realistischer.

-= kenne ich gar nicht...was soll der bewirken?
 
Original geschrieben von won_gak
Sorry, ich hatte da noch das falsche drin.

-= statt %=

Ich bin auch verwirrt. Der bekannte Zeitpunkt (20 Uhr) ist doch immer beim END-Zeitpunkt, und nicht beim aktuellen timestamp? Du hast aber bei mktime () 20 stehen bei den Stunden... das kann logisch nicht ganz gehen.
Oh shit :rolleyes:
Die 20 Uhr müssen ja wirklich in die andere Timestamp rein...
Peinlich, Peinlich ;)
Ich werd mir das ganze nochmal durch den Kopf gehen lassen,
sprich: ich geh jetzt schlafen :)
Morgen gehts dann weiter, vielleicht ist mein Kopf dann klarer...
 
Zurück