#native_company# #native_desc#
#native_cta#

Date/Time Count Down

By Tom Gard
on January 9, 2001

Version: 1.27

Type: Sample Code (HOWTO)

Category: Calendars/Dates

License: GNU General Public License

Description: PHP Count down days:hours:minutes:seconds between current date/time and future date/time. I’m a newbie and would appreciate any feedback on my code. Perhaps there is a better/simpler way to do this in php and if so please fill me in, thanks.

<?php
//Count Down of Days:Hours:Minutes:Seconds
//by T.Gard ([email protected]) written 01/09/2001
//
//Date/Time counting down too.
$datetime=strtotime( "2001-01-27 11:00" );
//Retrieve the current date/time  
$date2=strtotime("NOW"); 


 if ($datetime < $date2) {
     print "The Event is here!! or over with!! <br>  ".$date2." is greater than ".$datetime."<br>";
 } else {
   
//List total time by type
//Seconds
echo "total seconds remaining: ".(($datetime-$date2)). "<br>";
$holdtotsec=(($datetime-$date2));
//Minutes
echo "total minutes remaining: ".(($datetime-$date2)/60). "<br>";
$holdtotmin=(($datetime-$date2)/60);
//Hours
echo "total hours remaining: ".(($datetime-$date2)/3600). "<br>";
$holdtothr=(($datetime-$date2)/3600); 
//
//Days - a day is a 24 hour period
//This gives days remaining
$holdtotday=intval(($datetime-$date2)/86400);
echo "total days remaining: ".$holdtotday. "<br>"; 
//
//Find hours remaining - get days in hours and sub from tothr
$holdhr=intval($holdtothr-($holdtotday*24));	
echo "hours remaining: ".($holdhr). "<br>";
//
//Find minutes remaining - get days and hours in minutes and sub from totmin
$holdmr=intval($holdtotmin-(($holdhr*60)+($holdtotday*1440))); 
echo "minutes remaining: ".($holdmr). "<br>";
//
//Find seconds remaining - get days hours minutes in seconds and sub from totsec
$holdsr=intval($holdtotsec-(($holdhr*3600)+($holdmr*60)+(86400*$holdtotday))); 
echo "seconds remaining: ".($holdsr). "<br>";
 }
?>