#native_company# #native_desc#
#native_cta#

Simple but very modifiable PHP countdown to specified date

By Aaron
on February 25, 2008

Version: 1.2

Type: Sample Code (HOWTO)

Category: Calendars/Dates

License: GNU General Public License

Description: This you guys can just copy and paste right into the body on a php page. It will display the days, hours, and minutes until the date and time you specify. If you want the is the variable for seconds made for you to use. It also has a nice little function that changes what is displayed depending on if the result is more than one or less than one. In this case it displays either “days” or “day” to let the company know the estimated time for updating the server. So use for whatever you want. I know I’ve snipped plenty of code myself!! Always a very useful tool when learning a new language. This also my first time ever submitting anything so any tips or comments you’ve got are appreciated.

	  <?
	
	 /***************************************************************************************************
	 ****************************************************************************************************                                                
	 **     	    A. Segal >> free for use and modification << 2008.02.25 04:37  					   **	
	 **			    Email: [email protected]                                     ** 
	 **     	    For info on the 'strtotime' function parameters...go to PHP.net                    **                                                                                        
	 ****************************************************************************************************																
	 ****************************************************************************************************/
	 
	//If anyone is feeling inspired -- give me an idea on how you would set this up to auto correct for Time Zones.... 
	  
// begin 'ETC' (Estimated Time of Completion) func...

	  
// set 'ETC' date & time for event -- currently set for 12:01 am Feb.27th 2008 C.S.T. -- !!allow for server time!! ...
//Adjust the event $integer to set time	  
$event=strtotime( "2008-02-27 01:01" );
	  
//Get Current Time from Server --- VERY IMPORTANT --- THIS MAY OR MAY NOT BE YOUR SITE'S LOCAL TIME.  

	    
$currentTime=strtotime("NOW"); 
	  
if ($event < $currentTime) {
	  
echo "<span class='style29'>We should be up and running very shortly and apologize for any inconvienience... please feel free to email or call if this is an emergency.</span><br>  ";
	 
 } 
 
 else {
// variables are pretty self explainatory ....60 seconds in a minute 60 minutues in an hour 24 hours in a day, etc+++

$totalsec=(($event-$currentTime));
$totalmin=(($event-$currentTime)/60);
$totalhr=(($event-$currentTime)/3600);
$totalday=intval(($event-$currentTime)/86400);
$hr=intval($totalhr-($totalday*24));
$mn=intval($totalmin-(($hr*60)+($totalday*1440)));
// seconds can be displayed ( int created but not displayed in page here)
$sec=intval($totalsec-(($hr*3600)+($mn*60)+(86400*$totalday)));
 }
  ;
?>
<!-- php results displayed within HTML adjust as necessary-->

	  
	  <?
	  //if event is past, make sure nothing displays besides what you choose display for when you have reached the completion date 
	  //here the last variable displayed is the minutes so check if any are left before your event if not don't display whatever static message you use
	  
	  if ($mn > 0) {
	  
	  echo "Estimated completion time:&nbsp;";
	  
	  }
	  
	  else {
	  
	  echo "";
	  
	  }
	  ;
	  ?>
	  
	
	  <? 
	  
	   //check if exists 
	  if ($totalday > 0){
	   echo "$totalday";
	  }
	  
	  else {
	  echo "";
	   }
	 ;
	 ?>
	  
	  <?
	  
	  //check which to display singular or plural nouns depending on amount of 
	  //days, hours, minutes..for this site. same for any results you need.
//also checks to make sure int exists
	  
	  if ($totalday > 1){
	  
	  echo "days";
	  
	  }
	  
	  else if ($totalday == 0) {
	  
	 echo"";
	 
	 }
	 
	 else {
	  
	  echo "day";
	  
	  }
	  
	  ?>
	  <? 
	  
	   //check if exists 
	  if ($hr > 0){
	   echo "$hr";
	  }
	  
	  else {
	  echo "";
	   }
	 ;
	 ?>
	  	  
	  
	  <?
	  
	  if ($hr > 1){
	  
	  echo "hours";
	  
	  }
	  
	  else if ($hr == 0){ 
	  
	  echo "";
	  
	  }
	  else{
	  
	  echo "hour";
	  };
	  
	  
	  ?>
	    <? 
	  
	   //check if exists 
	  if ($mn > 0){
	   echo "$mn";
	  }
	  
	  else {
	  echo "";
	   }
	 ;
	 ?>
	  
	  	  <?
	  
	  if ($mn > 1){
	  
	  echo "minutes";
	  
	  }
	  
	  else if ($mn == 0){ 
	  
	  echo "";
	  
	  }
	  
	  else{
	  echo "minute";
	  }
	;  
	  ?>