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

eskiesirius's avatar

Add interval in the querying date

This is my database structure:

id | duration | used_at | status
1   |    1   |  2022-01-22 02:40:11 | used

and my query is this:

public function scopeExpiringSubscription($query)
    {
        return $query
            ->withoutGlobalScopes()
            ->whereRaw("DATE_ADD(used_at, INTERVAL duration MONTH) < NOW()")
            ->where('status', self::USED);
    }

but i got this error SQLSTATE[HY000]: General error: 1 near "duration": syntax error (SQL: select * from "vouchers" where DATE_ADD(used_at, INTERVAL duration MONTH) < NOW() and "status" = used)

0 likes
2 replies

Please or to participate in this conversation.