gabrielp Posted January 2, 2009 Share Posted January 2, 2009 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) Quote Link to comment Share on other sites More sharing options...
gabrielp Posted January 2, 2009 Author Share Posted January 2, 2009 Here you have sample data: $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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 2, 2009 Share Posted January 2, 2009 Why don't you just use the strotime function to do the figuring? <?php $date_term = strtotime($myrow['start_date'] . ' + ' . $myrow['type'] . ' months'); if (time() <= $date_term) { // // ok // } else { // // not ok // } ?> Ken Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2009 Share Posted January 2, 2009 $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 } Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted January 2, 2009 Share Posted January 2, 2009 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 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 2, 2009 Share Posted January 2, 2009 I really have to learn the MySQL way of doing dates & times... Ken Quote Link to comment Share on other sites More sharing options...
gabrielp Posted January 5, 2009 Author Share Posted January 5, 2009 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!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.