skip to Main Content

How to return TRUE when an account was created more than 30 days ago?

I have the following date:

$udata['joined']; – record date in time():

I tried like this

If($udata['joined'] = strtotime ("+30 days", time())){
    return true;
}

Any idea why it’s not working correctly?

Return empty.

2

Answers


  1. You are assigning a value instead of using an operator, i.e. you are using = instead of ==. Try this:

    If($udata['joined'] == strtotime ("+30 days", time())){
        return true;
    }
    

    Edit

    As others pointed out, checking for equality will most likely always return false anyway, because you’d be very luck to hit the exact same timestamp!

    What you are looking for is the <= (less than or equal) operator to check if $udata['joined'] is a timestamp before 30 days ago. In other words :

    // true if the provided date is before 30 days ago
    return strtotime($udata['joined']) < strtotime("-30 days", time());
    
    Login or Signup to reply.
  2. I guess you want

    If timestamp is smaller than (or exactly) 30 days ago

    if ($udata['joined'] <= strtotime("-30 days", time()) {
        return TRUE;
    }
    

    (you need to substract 30 days from now and remove all syntax errors)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search