Blog
PreviousNext

Useful Query Builder Date Helpers for Invoices

Learn how to use Query Builder date helper methods like wherePast, whereFuture, and whereToday to easily filter invoice records by due dates.

30c1c78d-6109-11f0-8000-525599bbc211

📊 Introduction

When working with invoices, filtering records by dates is a very common requirement.
Instead of manually writing complex conditions, Query Builder provides convenient date helper methods that make our job much easier.

Let’s say we have an invoices table with a due_at column.
Here are some useful helpers you can use right away:


🔹 Date Helper Methods

1) wherePast('due_at')

Fetches invoices where due_at is before the current date/time.

Invoice::wherePast('due_at')->get();

2) whereFuture('due_at')

Fetches invoices where due_at is after the current date/time

Invoice::whereFuture('due_at')->get();

3) whereNowOrPast('due_at')

Fetches invoices where due_at is either in the past or exactly now.

Invoice::whereNowOrPast('due_at')->get();

4) whereNowOrFuture('due_at')

Fetches invoices where due_at is either in the future or exactly now.

Invoice::whereNowOrFuture('due_at')->get();

5) whereToday('due_at')

Fetches invoices where due_at falls within today’s date.

Invoice::whereToday('due_at')->get();

6) whereBeforeToday('due_at')

Fetches invoices where due_at is before today (not including today).

Invoice::whereBeforeToday('due_at')->get();

7) whereAfterToday('due_at')

Fetches invoices where due_at is after today (not including today).

Invoice::whereAfterToday('due_at')->get();