Advertisement

05.19.2008 at 03:30PM PDT, ID: 23415415
[x]
Attachment Details

PHP Time Until Timestamp (Countdown - Days, Hours, Minutes, Seconds)

Asked by sgcity in PHP Scripting Language

Tags: PHP, Firefox 2.0, Internet Explorer 7

Currently working on grabbing a future timestamp and subtracting it from the current time to display a live on refresh countdown timer. It should display days, hours, minutes, seconds until the time arrives, I've got the days displaying easily, but for the time I suppose making the current time relevant should work. Time is relevant to the server. The code may seem a bit confusing, but all this time stuff is racking my brain. I hope someone can help me out, I think there's just a quirk in my code.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
// GENERATE TIME LEFT
  // -------------
  $EndTime = $row['EndTime'];
  // -------------
  $EndDay = ($EndTime - time())/86400;
  $EndDay = floor($EndDay);
  $EndHours = ($EndTime - mktime(date("H"),date("i"),date("s"),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)))/3600;
  if(abs($EndHours) != $EndHours){
    $EndHour = (24-date("H"))+date("H", mktime(date("H", $EndTime),date("i", $EndTime),date("s", $EndTime),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)));
    $EndHour = floor($EndHour);
  }else{
    $EndHour = floor($EndHour);
  }
  $EndMins = ($EndTime - mktime(date("H", $EndTime),date("i"),date("s"),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)))/60;
  if(abs($EndMins) != $EndMins){
    $EndMin = (60-date("i"))+date("i", mktime(date("H", $EndTime),date("i", $EndTime),date("s", $EndTime),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)));
    $EndMin = floor($EndMin);
  }else{
    $EndMin = floor($EndMin);
  }
  $EndSecs = ($EndTime - mktime(date("H", $EndTime),date("i", $EndTime),date("s"),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)));
  if(abs($EndSecs) != $EndSecs){
    $EndSec = (60-date("s"))+date("s", mktime(date("H", $EndTime),date("i", $EndTime),date("s", $EndTime),date("m", $EndTime),date("d", $EndTime),date("Y", $EndTime)));
    $EndSec = floor($EndSec);
  }else{
    $EndSec = floor($EndSec);
  }
 
echo $EndDay." Days ".$EndHour." Hours ".$EndMin." Mins ".$EndSec." Secs Left";
 
Loading Advertisement...
 
[+][-]05.19.2008 at 03:41PM PDT, ID: 21602218

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 07:17PM PDT, ID: 21603158

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 07:20PM PDT, ID: 21603181

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: PHP, Firefox 2.0, Internet Explorer 7
Sign Up Now!
Solution Provided By: philjones85
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.20.2008 at 07:22AM PDT, ID: 21606395

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628