TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Stuck with timestamps (http://www.talkphp.com/general/3473-stuck-timestamps.html)

KingOfTheSouth 10-13-2008 08:11 PM

Stuck with timestamps
 
I own a online game and have subscriptions to the game and I am trying to get the subscriptions last only last 30 days which I am having trouble with..

php Code:
if($user["status"] == 3)
        {
            $sup = "No, <a href='credits.php?action=purchase'>Want to be one?</a>";
        }else{
            $sup = "Yes";
        }

if($user["substatus"] == 0)
        {
            $sub = "No";
        }
        elseif($user["substatus"] == 1)
        {
            $sub = "Level One (+5 turns / +500hold)";
        }
        elseif($user["substatus"] == 2)
        {
            $sub = "Level Two (+10 turns / +1,000hold)";
        }
                elseif($user["substatus"] == 3)
        {
            $sub = "Level Two (+15 turns / +1,500hold)";
        }


if($user["substatus"] == 1){$length = 1199145600;}
if($user["substatus"] == 2){$length = 1199145600;}
if($user["substatus"] == 3){$length = 1199145600;}

$expire = $subtime["datebought"]+$length;


Here is the code I just cannot make them only last 30 days. If you can help me please I will appreciate it

ReSpawN 10-13-2008 08:17 PM

First off, you should formulate your variables and so forth.

The most wise thing to do, is to, when people register, post a timestamp with just the time() function or
PHP Code:

list( $microTime$timeStamp ) = explode" "microtime() );
$registerDate = ( $microTime $timeStamp );

// Or just do this, which is more general but easy. microtime() is only used for timestamp and so forth (query time etc.)
$registerDate time(); 

That returns the date which can be transformed like so;
PHP Code:

print( date'H:i:s d-m-Y'$registerDate ) ); 

This returns it in every format you want.

If this is not what you mean, please formulate your post a bit more accurate and tell me what your plan is.

KingOfTheSouth 10-13-2008 08:19 PM

Well I am not that good at coding I taught myself everything I know but I will give it a shot..

Wildhoney 10-13-2008 09:11 PM

It is quite simple, you'll just have to find a place in your code to insert it. I hope it helps you!

php Code:
function has_subscription_expired($iTimestamp, $iDays = 30)
{
    $iNadir = strtotime(sprintf('-%d days', $iDays));
   
    if ($iTimestamp < $iNadir)
    {
        return true;
    }
   
    return false;
}

var_dump(has_subscription_expired(strtotime('-35 days'))); // true
var_dump(has_subscription_expired(strtotime('-30 days'))); // false
var_dump(has_subscription_expired(strtotime('-25 days'))); // false
 

Tanax 10-13-2008 10:29 PM

Could you please explain this for me please:
PHP Code:

strtotime(sprintf('-%d days'$iDays)) 

I know how sprintf works. I just don't understand why you write "days" in there??
And same thing when you use the function, you write
PHP Code:

(strtotime('-25 days')) 

Why "days" there?? :S And why a MINUS ?? :O

Wildhoney 10-13-2008 11:11 PM

You're deducting 25 days off the current date with that command. You can do plus and minuses. As well as days, years, seconds, months, et cetera...

KingOfTheSouth 10-14-2008 12:50 AM

I get what you are saying. I just really needed help with that because my partner is out of the country and he does all of the coding that is what he does for a living. But thanks alot


All times are GMT. The time now is 05:52 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0