Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

socieboy's avatar

Check if date string is equal to the las 5 days

I want to know if a user was registered in the last 5 days.

But the only thing is a string date. like that

$date = "2015-08-03 11:52:52";

How do I check that with Carbon or simple PHP

0 likes
2 replies
milroy's avatar

@socieboy

$dt = Carbon::parse('2015-08-03 11:52:52');
$now    = Carbon::now();
$from   = Carbon::now()->subDays(5);

if($dt->between($from, $now)))
{
    // true
}

Please or to participate in this conversation.