<?php
function countdown($targetDate) {
// Fehlermeldung, falls das Datum erreicht/berschritten wurde, hinter das Fragezeichen schreiben.
$errorMessage = '0 Tage, 0 Monate, 0 Jahre, 0 Stunden, 0 Minuten, 0 Sekunden';
foreach ($targetDate as $test) if (!is_integer($test)) die('Fehlerhafte Zieldatumsangabe in Funktion countdown()');
$todayDate['day'] = date('d');
$todayDate['month'] = date('m');
$todayDate['year'] = date('Y');
$todayDate['hour'] = date('H');
$todayDate['minute'] = date('i');
$todayDate['second'] = date('s');
if (($todayDate['year'] > $targetDate['year']) || (($todayDate['year'] == $targetDate['year']) && ($todayDate['month'] > $targetDate['month'])) || (($todayDate['year'] == $targetDate['year']) && ($todayDate['month'] == $targetDate['month']) && ($todayDate['day'] > $targetDate['day']))) return $errorMessage;
else {
if ($todayDate['second'] > $targetDate['second']) {
$countdown['seconds'] = (60 - $todayDate['second']) + $targetDate['second'];
$sub['minute'] == TRUE;
}
else $countdown['seconds'] = $targetDate['second'] - $todayDate['second'];
if ($todayDate['minute'] > $targetDate['minute']) {
$countdown['minutes'] = (60 - $todayDate['minute']) + $targetDate['minute'];
$sub['hour'] == TRUE;
}
else $countdown['minutes'] = $targetDate['minute'] - $todayDate['minute'];
if ($sub['minute']) $countdown['minutes']--;
if ($todayDate['hour'] > $targetDate['hour']) {
$countdown['hours'] = (24 - $todayDate['hour']) + $targetDate['hour'];
$sub['day'] == TRUE;
}
else $countdown['hours'] = $targetDate['hour'] - $todayDate['hour'];
if ($sub['hour']) $countdown['hours']--;
$zeiger = FALSE;
$countdown['days'] = 0;
if (($todayDate['year'] == $targetDate['year']) && ($todayDate['month'] == $targetDate['month']) && ($todayDate['day'] == $targetDate['day'])) $zeiger = TRUE;
while(!$zeiger) {
if (checkdate($todayDate['month'], $todayDate['day']+1, $todayDate['year']))
$todayDate['day']++;
elseif (checkdate($todayDate['month'] + 1, '1', $todayDate['year'])) {
$todayDate['month']++;
$todayDate['day'] = 1;
}
else {
$todayDate['year']++;
$todayDate['month'] = 1;
$todayDate['day'] = 1;
}
if (($todayDate['year'] == $targetDate['year']) && ($todayDate['month'] == $targetDate['month']) && ($todayDate['day'] == $targetDate['day'])) $zeiger = TRUE;
else $countdown['days']++;
}
if ($sub['day']) $countdown['days']--;
if ($countdown['days'] < 0) return $errorMessage;
else return 'Noch '.$countdown['days'].' Tage, '.$countdown['hours'].' Stunden, '.$countdown['minutes'].' Minuten und '.$countdown['seconds'].' Sekunden.';
// oben: Meldung, wieviele Tage (Stunden, Minuten, Sekunden) es noch dauert, bis der Countdown abgelaufen ist, hinter das "return" schreiben.
}
}
##### Das Datum, bis zum dem der Countdown laufen soll #####
// Tag
$targetDate['day'] = 5;
// Monat
$targetDate['month'] = 4;
// Jahr
$targetDate['year'] = 2006;
// Stunde
$targetDate['hour'] = 7;
// Minute
$targetDate['minute'] = 45;
// Sekunde
$targetDate['second'] = 23;
// Funktionsaufruf der Funktion countdown();
echo countdown($targetDate);
## (C) by GNU
## coded by loli
?>