ababmxking Posted July 3, 2008 Share Posted July 3, 2008 $year = mysql_fetch_object(mysql_query("SELECT end YEAR FROM roundslog WHERE ended='No' AND end>'$date2'")); $month = mysql_fetch_object(mysql_query("SELECT end MONTH FROM roundslog WHERE ended='No' AND end>'$date2'")); $day = mysql_fetch_object(mysql_query("SELECT end DAY FROM roundslog WHERE ended='No' AND end>'$date2'")); $hour = mysql_fetch_object(mysql_query("SELECT end HOUR FROM roundslog WHERE ended='No' AND end>'$date2'")); $minute = mysql_fetch_object(mysql_query("SELECT end MINUTE FROM roundslog WHERE ended='No' AND end>'$date2'")); $seconds = mysql_fetch_object(mysql_query("SELECT end SECOND FROM roundslog WHERE ended='No' AND end>'$date2'")); } // Define your target date here $targetYear = $year; $targetMonth = $month; $targetDay = $day; $targetHour = $hour; $targetMinute= $minute; $targetSecond= $seconds; // End target date definition // Define date format $dateFormat = "Y-m-d H:i:s"; $targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear); $actualDate = time(); $secondsDiff = $targetDate - $actualDate; $remainingDay = floor($secondsDiff/60/60/24); $remainingHour = floor(($secondsDiff-($remainingDay*60*60*24))/60/60); $remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60); $remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60)); $targetDateDisplay = date($dateFormat,$targetDate); $actualDateDisplay = date($dateFormat,$actualDate); ?> <link href="style/style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var days = <?php echo $remainingDay; ?> var hours = <?php echo $remainingHour; ?> var minutes = <?php echo $remainingMinutes; ?> var seconds = <?php echo $remainingSeconds; ?> function setCountDown () { seconds--; if (seconds < 0){ minutes--; seconds = 59 } if (minutes < 0){ hours--; minutes = 59 } if (hours < 0){ days--; hours = 23 } document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds"; setTimeout ( "setCountDown()", 1000 ); } </script> <?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds"; ?> i got this off of hotscripts. ok say the End date is 2008-07-07 18:37:23 and the current date is 2008-07-02 23:53:27 this is what the countdown writes. -2740 days, 2 hours, 7 minutes, 34 seconds this whole script confuses the hell out of me so im asking for some help. Quote Link to comment Share on other sites More sharing options...
vbnullchar Posted July 3, 2008 Share Posted July 3, 2008 try this.. <?php function log_days_ago($start_date, $end_date=NULL) { if($end_date == NULL) { $end_date = strtotime('now'); } $days = intval( ($end_date - $start_date) / 86400 ); $tmp = ($end_date - $start_date) % 86400; $hours = intval($tmp / 3600); $tmp = $tmp % 60; $minutes = intval($tmp / 60); $tmp = $tmp % 60; $seconds = $tmp; $diff = ($days == 0) ? "" : $days.' day(s) '; $diff.= ($hours == 0) ? "" : $hours.' hours(s) '; $diff.= ($minutes == 0) ? "" : $minutes.' minutes(s) '; $diff.= 'ago..'; return $diff; } echo log_days_ago( strtotime('2008-07-02 23:53:27'), strtotime('2008-07-07 18:37:23') ); ?> Quote Link to comment Share on other sites More sharing options...
ababmxking Posted July 3, 2008 Author Share Posted July 3, 2008 ok functions arent my thing idk how to read them most of the time. this is what i did and it just echos ago... $date2 = date('Y-m-d H:i:s'); $dateee = mysql_fetch_object(mysql_query("SELECT * FROM roundslog WHERE ended='No' AND end>'$date2'")); if($ulvl == 5){ $year = mysql_fetch_object(mysql_query("SELECT end YEAR FROM roundslog WHERE ended='No' AND end>'$date2'")); $month = mysql_fetch_object(mysql_query("SELECT end MONTH FROM roundslog WHERE ended='No' AND end>'$date2'")); $day = mysql_fetch_object(mysql_query("SELECT end DAY FROM roundslog WHERE ended='No' AND end>'$date2'")); $hour = mysql_fetch_object(mysql_query("SELECT end HOUR FROM roundslog WHERE ended='No' AND end>'$date2'")); $minute = mysql_fetch_object(mysql_query("SELECT end MINUTE FROM roundslog WHERE ended='No' AND end>'$date2'")); $seconds = mysql_fetch_object(mysql_query("SELECT end SECOND FROM roundslog WHERE ended='No' AND end>'$date2'")); } function log_days_ago($start_date, $end_date=NULL) { if($end_date == NULL) { $end_date = strtotime('now'); } $days = intval( ($end_date - $start_date) / 86400 ); $tmp = ($end_date - $start_date) % 86400; $hours = intval($tmp / 3600); $tmp = $tmp % 60; $minutes = intval($tmp / 60); $tmp = $tmp % 60; $seconds = $tmp; $diff = ($days == 0) ? "" : $days.' day(s) '; $diff.= ($hours == 0) ? "" : $hours.' hours(s) '; $diff.= ($minutes == 0) ? "" : $minutes.' minutes(s) '; $diff.= 'ago..'; return $diff; } echo log_days_ago( strtotime('$date2'), strtotime('$dateee->end') ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.