Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How(in wordpress multisite) can i get id of users, who signed up 30 days ago, or more? I am building free trial system for 30 days. I want to have a function, that check when user signed up, and how many days have passed. The function should return number of days that passed.

It's easy to get user signed up time:

global $current_user;
get_currentuserinfo();
echo $current_user->user_registered;

It's echo:

2012-09-16 6:25:47

Now, how to check how many days passed from above time?

share|improve this question
add comment

3 Answers 3

There's the function human_time_diff( $from, $to );, which will compare two UNIX timestamps. Just use mktime() on $GLOBALS['current_user']->user_registered; and compare it with the current UNIX time.

share|improve this answer
add comment

If you wanted to do it more systematically using a script you could do something like this

$timestamp_start = strtotime($startdate);
$timestamp_end = strtotime($enddate);
$difference = abs($timestamp_end - $timestamp_start);

Then have you can write a script that will check if it's been greater than 30 days

if ($difference >= 2592000){
//send invite code
}

You can also get a rounded version of just the days by doing this

$days = floor($difference/(60*60*24));
echo 'Days '.$days;

Source

share|improve this answer
add comment

Thank You for your answer, I combine your solutions, and it works!

human_time_diff, does not fit to my script, becouse it's return minutes, houers, and days with "ago" word. So, i create my own function that return only days without "ago".

Function code:

function count_days($from){

    $start_time = $from;
    $current_time = time();

    //convert given date to the unix time (in seconds)
    $unix_start_time = date("U",strtotime($start_time));

    //count the difference between current time and given date
    $diff = (int) abs($current_time - $unix_start_time);

    //Now, we change seconds for days
    if ($diff >= 86400) {
        $days = round($diff / 86400);
        if ($days <= 1) $days = 1;  
    }

    //returns days
    return $days;
}

First parametr of function is date, for example 22-09-2012. Next, this date is converted to unix seconds, and then we can subtract current time from this date. This way, we can calculate the days that have passed since a given date. Yay!

Thanks again!

share|improve this answer
1  
human_time_diff doesn't append the word 'ago'... –  Stephen Harris Sep 22 '12 at 22:14
    
Oh, yes, sorry, it's my mistake. But anyway, human_time_diff, can return number of minutes, or hours. I want only get the number of days. Also my time format is 'd-m-Y', so i need to convert time to unix seconds. –  Jacek Jagiełło Sep 22 '12 at 22:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.