Scope to get all records that have anniversary within the next two weeks

Posted 1 month ago by mstnorris

Based on a date field, I would like to retrieve all records that have an anniversary within the next two weeks using a query scope.

I can get all records where today is the anniversary using the following:

public function scopeTodayIsAnniversary($query)
{
    return $query->whereMonth('started_on', Carbon::now())
        ->whereDay('started_on', Carbon::now());
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.