Problem with date 2009

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gabrielp
Forum Newbie
Posts: 5
Joined: Fri Jul 23, 2004 12:29 pm

Problem with date 2009

Post 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!
Last edited by gabrielp on Fri Jan 02, 2009 12:12 pm, edited 1 time in total.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: Problem with date 2009

Post by jmut »

No clue at all what is this supposed todo. Can you give sample input data. $myrow that is and what should happen
gabrielp
Forum Newbie
Posts: 5
Joined: Fri Jul 23, 2004 12:29 pm

Re: Problem with date 2009

Post 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!!!
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: Problem with date 2009

Post 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.
Post Reply