XF 2.1 Update finder to only find within last 24 or 72 hours

HJW

Active member
Hello,

I'm trying to update a finder to only return users with a ban date of within the last 24 or 72 hours

Code:
            $users = $finder
                ->with('Ban')
                ->where('is_banned',1)
                ->where('message_count','>',100)
                ->order('Ban.ban_date','DESC')
                ->limit($limit)
                ->fetch();

Looking at other code this seems to work to find for the current day, but is this the right kind of thing to use to find for the current day, but can this easily be adjusted to last 24 or 72 hours?
Code:
                    $date = new \DateTime("now", new \DateTimeZone($visitor['timezone']));
                    $date->setTime(0, 0, 0);
                    $start = $date->getTimestamp();
 

Lukas W.

Well-known member
PHP:
// Current day
$finder->where('Ban.ban_date', '>=', \XF::$time - \XF::$time % 86400);

// Last 24 hours
$finder->where('Ban.ban_date', '>=', \XF::$time - 86400);

// Last 72 hours
$finder->where('Ban.ban_date', '>=', \XF::$time - 86400 * 3);
 
  • Love
Reactions: HJW
Top