Jump to content

[SOLVED] Problem with date 2009


gabrielp

Recommended Posts

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

 

<?php
$myrow = mysql_fetch_array($result);
                    
$date_activation = $myrow['start_date'];
$months = $myrow['type'];

$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!

 

(edited to change tags to


tags)

Link to comment
Share on other sites

$myrow = mysql_fetch_array($result);
                    
$date_activation = $myrow['start_date'];
$months = $myrow['type'];

$timestamp_activation = strtotime($date_activation);
$timestamp_type = strtotime("$months months ago");
if ($timestamp_activation < $timestamp_type) {
  //subscription expired
} 

Link to comment
Share on other sites

That's a pretty nasty way of checking if they're active or not. I'd do much more of the work with mysql:

(Edit: Comment wasn't directed at you Mchl or Ken; but i'd still do the work with mysql.)

 

$sql = "SELECT COUNT(*) FROM yourtable WHERE username='$username' AND start_date + INTERVAL type MONTH >= CURDATE()";
$result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR);
if(mysql_resut($result,0) > 0){
//active subscription
}else{
//subscription ended.
}

 

Im assuming that you're start_date field has type DATE, your type field contains the number of months of their subscription and you have a field called username

Link to comment
Share on other sites

Thank you all guys !!!! I finally used

 

 

$myrow = mysql_fetch_array($result);

                   

$date_activation = $myrow['start_date'];

$months = $myrow['type'];

 

$timestamp_activation = strtotime($date_activation);

$timestamp_type = strtotime("$months months ago");

if ($timestamp_activation < $timestamp_type) {

  //subscription expired

}

 

but I will try the mySql way too :)

 

Thanks!!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.