i need a "counter" so to speak that will say how many

-years
-months
-weeks
-days

left until a set date... i dont need any clock output, e.g. minutes, hours, seconds and it doesnt have to update in real time.. just when the page refreshes

having trouble googling for it and not finding something overly complicated

any help is def appreciated!

thanks

    Pass the timstamp to this function

    
    function cal_time_for_lastseen($timestamp)
    	{
    		$content = '';
    
    	$days_gone = "Days..,";
    	$hours_gone = "Hou..,";
    	$mins_gone = "Mins..";
    	$secs_gone = "Sec..";
    
    	$events_time = $timestamp;
    
    	$time_left = time() - $events_time;
    	$days_passed = gmdate("z",$time_left);
    	$hours_passed = gmdate("G",$time_left);
    	$mins_passed = gmdate("i",$time_left);
    	$secs_passed = gmdate("s",$time_left);
    
    	if ($days_passed == 0)
    	{
    		$days_passed = '';
    		$days_gone = ''; 
    	}
    	if ($hours_passed == 0)
    	{
    		$hours_passed = '';
    		$hours_gone = ''; 
    	}		
    	if ($mins_passed == 0)
    	{
    		$mins_passed = '';
    		$mins_gone = ''; 
    	}
    	if ($secs_passed == 0)
    	{
    		$secs_passed = '';
    		$secs_gone = ''; 
    	}				
    	$content .= "$days_passed $days_gone $hours_passed  $hours_gone  $mins_passed  $mins_gone ";
    	return $content;
    }
    

      i ask b/c i tried:

      counter(mktime(0,0,0,8,11,2007));
      

      where counter is the name of your function... it says there are 4 days, 20 hours and some odd minutes until august 11th 2007

        The code you were given did not work because it was calculating time since a date has passed. Below is a function that counts down until a certain date. I tried to make it very easy to understand so that you understand the concept and modify it however you need.

        
        <?php
        
        function calculateTimeLeft($timestamp) {
        	$days = 0;
        	$hours = 0;
        	$minutes = 0;
        	$seconds = 0;
        	$str = "";
        
        $now = time();
        $timeLeft = $timestamp-$now;
        while ($timeLeft > 86400) 
        	//while still bigger than a day
        	$timeLeft = $timeLeft - 86400;
        	$days++;
        }
        
        while ($timeLeft > 3600) {
        	//while still bigger than a hour
        	$timeLeft = $timeLeft - 3600;
        	$hours++;
        }
        
        while ($timeLeft > 60) {
        	//while still bigger than a minute
        	$timeLeft = $timeLeft - 60;
        	$minutes++;
        }
        
        //All thats left is how many seconds there are
        $seconds = $timeLeft;
        
        $str .= $days . " days ";
        $str .= $hours . " hours ";
        $str .= $minutes . " minutes ";
        $str .= $seconds . " seconds ";
        
        return $str;
        }
        
        
        echo "There are " . calculateTimeLeft(mktime(0,0,0,12,25,2006)) . " left until Christmas<br>\n";
        
        
        
        ?>
        
        

        -Jason

          ok ill try to hack that later to give years, months and weeks

            Write a Reply...