Page 1 of 1

Problem with date 2009

Posted: Fri Jan 02, 2009 10:58 am
by gabrielp
Hi,

I have been using the following code all 2008 , it checks if user is active, check last activation date, number of months paid, add that time to the last activation date and also check if date is grater than actual date.

It worked great until Jan 1st, when I guess there's a problem with users with active accounts on 2008 and months calculation with 2009

Code: Select all

 
$myrow = mysql_fetch_array($result);
                    
$date_activation = $myrow['start_date']; // Sample date: "2008-12-18 08:00:47"
$months = $myrow['type']; // Sample value = 1 (means 1 month) or 12 means 12 months
 
$date_now = date("Y-m-d h:m:s", time());
$qty_years=floor($months/12);
$qty_months=$months%12;
 
$bits=explode("-",$date_activation);
$year=$bits[0];                     
$month = sprintf('%02d',$bits[1]);
$newyear=$year+$qty_years;
$newmonth=sprintf('%02d', $month+$qty_months);
 
$date_expires=$newyear."-".$newmonth."-".$bits[2];
 
if ($date_now <= $date_expires) 
    
    {
    
                // user is active, write a cookie and say welcome
                
    }  else {
    
    // subscription expired
        
 
    }
 
 
Thanks for all the help that you can provide!

Re: Problem with date 2009

Posted: Fri Jan 02, 2009 11:38 am
by jmut
No clue at all what is this supposed todo. Can you give sample input data. $myrow that is and what should happen

Re: Problem with date 2009

Posted: Fri Jan 02, 2009 12:13 pm
by gabrielp
jmut wrote:No clue at all what is this supposed todo. Can you give sample input data. $myrow that is and what should happen
Sorry about that, I have now updated the code with sample entry data.
Hope this helps.

thanks!!!

Re: Problem with date 2009

Posted: Fri Jan 02, 2009 3:41 pm
by jmut
Trying to figure out 1min what it's supposed todo. Sorry can't figure. Hint: use strtotime() and work from there without those weird explodes etc + this type being months not sure what represents.