Jump to content

Creating count down timer in php??


radiations3

Recommended Posts

I am using the following code for the count down  but this code is not helping me to get the values of start date and ending date from my database

any idea how to do it or kindly provide me a working code that gets the value from the database and generate count down timer accordingly

 

<?php

$target = mktime(0, 0, 0, 2, 10, 2012) ;

$today = time () ;

$difference =($target-$today) ;

$days =(int) ($difference/86400) ;

print "Our event will occur in $days days";

?>

Link to comment
Share on other sites

  # Event Date
  $event_day   = 10;     
  $event_month = 2;      
  $event_year  = 2012;   
  # Today's Date in TIMESTAMP FORMAT
  $current_date = time();
  
  # Calculate the difference
  $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - $current_date) / 3600);
  # Format
  $days_left  = (int) ($difference / 24);
  
  # Print our results
  print $days_left . ' days left until ' . $event_day . '-' . $event_month.'-'.$event_year;

 

 

Link to comment
Share on other sites

<?php
   
  $date = strtotime('02/10/12 01:07:30 AM'); // Just put in between these two parenthesis the date, wherever it may come from.
  $event_year = date('Y',$date);
  $event_month = date('n',$date);
  $event_day = date('j',$date);
    
  $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - time()) / 3600);
  $days_left  = (int) ($difference/24);
  
  print $days_left;
  
?>

Link to comment
Share on other sites

<?php
   
  $date = strtotime('02/10/12 01:07:30 AM'); // Just put in between these two parenthesis the date, wherever it may come from.
  $event_year = date('Y',$date);
  $event_month = date('n',$date);
  $event_day = date('j',$date);
    
  $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - time()) / 3600);
  $days_left  = (int) ($difference/24);
  
  print $days_left;
  
?>

 

can i do this with the following:

$date = strtotime('02/10/12 01:07:30 AM');

 

$enddate =  echo $row_Recordset2['date'];

$date = strtotime($enddate);

 

 

Link to comment
Share on other sites

yes i recently checked and yeah my issue is being solved one last question:

How can we create a countdown timer just like in the following url in which the time also gets minus and displayed dynamically? If you have any link or piece of code then kindly share i'll be very thankful to you and thanks alot for the help.....

 

http://www.groupon.com/

Link to comment
Share on other sites

Final piece of code thanks to phpSensei

 

<?php
  $check = '10/09/11'; // Set it to the recordset or a variable from where the date is comming from the specific field from database
  $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from.
  $event_year = date('Y',$date);
  $event_month = date('n',$date);
  $event_day = date('j',$date);
    
  $difference = ((mktime (0,0,0,$event_month,$event_day,$event_year) - time()) / 3600);
  $days_left  = (int) ($difference/24);
  
   print $days_left . ' days left until ' . $event_day . '-' . $event_month.'-'.$event_year; 
  ?>  

 

Kindly phpSensei answer my one last question i asked...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.