How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Get Records Created Today in Laravel
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Learn > Web Development > How to Get Records Created Today in Laravel
Web Development

How to Get Records Created Today in Laravel

how7o
By how7o
Last updated: April 20, 2026
6 Min Read
Laravel Eloquent records today — Carbon today helper and whereDate illustration
SHARE

Pulling laravel eloquent records today — rows whose created_at falls within the current calendar day — is a single whereDate call once you know the shape. This guide shows the canonical one-liner, the older-Laravel variant that needs an explicit operator, a Carbon-free alternative using now()->toDateString(), and a high-precision whereBetween form that actually uses your index on large tables.

Contents
  • TL;DR
  • The canonical one-liner
  • The older-Laravel variant with explicit =
  • Without a Carbon import: now()->toDateString()
  • High-precision range with whereBetween
  • Timezone watch-outs
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-21 on Laravel 11 with PHP 8.3 and MySQL 8.0. Originally published 2022-10-07, rewritten and updated 2026-04-21.

TL;DR

Import Carbon and run Post::whereDate('created_at', Carbon::today())->get(). On older Laravel versions add the explicit operator: whereDate('created_at', '=', Carbon::today()). For large tables, use the index-friendly range form: Post::whereBetween('created_at', [today()->startOfDay(), today()->endOfDay()])->get().

The canonical one-liner

Drop this at the top of the file that uses it:

use Carbon\Carbon;

Then query:

$posts = Post::whereDate('created_at', Carbon::today())->get();

Eloquent’s whereDate scope compiles to DATE(created_at) = ?, and Carbon’s today() returns today’s date at 00:00:00, which Laravel serializes as Y-m-d for the bind. The resulting query returns every row created between today’s midnight and tomorrow’s midnight.

The older-Laravel variant with explicit =

If you’re maintaining a project pinned to an older Laravel minor, you may see a runtime error complaining that whereDate is missing its third argument. The fix is to pass the operator explicitly:

$posts = Post::whereDate('created_at', '=', Carbon::today())->get();

Modern Laravel (8.x and up) accepts the two-argument form and implies =, so the explicit operator is optional — but never wrong. If you’re unsure which minor you’re on, running with the explicit operator is the safe default.

laravel eloquent records today — whereDate vs whereBetween range on created_at

Without a Carbon import: now()->toDateString()

Laravel’s global now() helper returns a Carbon instance, so you can get today’s Y-m-d string without adding a use line:

$posts = Post::whereDate('created_at', now()->toDateString())->get();

now()->toDateString() returns '2026-04-21' (or whatever today is). The scope still compiles to DATE(created_at) = ?; the only difference is cosmetic — one less import line.

High-precision range with whereBetween

whereDate is convenient but wraps created_at in a SQL function, which prevents MySQL from using a B-tree index on that column. On tables with hundreds of thousands of rows, swap to a timestamp range that the optimizer can serve with an index scan:

$posts = Post::whereBetween('created_at', [
    today()->startOfDay(),
    today()->endOfDay(),
])->get();

today() is a Laravel helper equivalent to Carbon::today(). startOfDay() returns YYYY-MM-DD 00:00:00, endOfDay() returns YYYY-MM-DD 23:59:59, and the resulting SQL is created_at BETWEEN ? AND ? — a plain range predicate that benefits from an index.

Benchmark both on your data before committing; for small tables (<10k rows) the difference is imperceptible and whereDate is more readable.

Timezone watch-outs

“Today” is relative to a timezone. Laravel reads config/app.php‘s timezone and sets PHP’s default accordingly, so Carbon::today() respects the app timezone. MySQL’s TIMESTAMP columns, however, are normalized to UTC under the hood. If app timezone and DB timezone disagree, rows inserted around midnight can appear to “belong” to the wrong day.

Two clean options: keep config/app.php as 'UTC' and convert for display, or pass an explicit zone to Carbon — Carbon::today('Asia/Dhaka')->setTimezone('UTC') — so the bind value matches the stored column’s zone.

Frequently asked questions

How do I get laravel eloquent records today in one line?

Use whereDate against Carbon::today(): Post::whereDate('created_at', Carbon::today())->get(). Laravel compiles the scope to DATE(created_at) = ? and binds today’s Y-m-d string. Remember to use Carbon\Carbon; at the top of the file, or reach for now()->toDateString() instead.

Why do I get “whereDate missing argument 3” on older Laravel?

Some Laravel 5.x builds require the explicit operator for whereDate: Post::whereDate('created_at', '=', Carbon::today())->get(). The two-argument form landed later. If you’re on a modern (8.x+) release you can drop the '=' — the error is a signal that you’re on an older minor.

Can I avoid importing Carbon entirely?

Yes. Laravel’s global now() helper returns a Carbon instance, so Post::whereDate('created_at', now()->toDateString())->get() works with zero explicit imports. Under the hood it’s still Carbon, but you don’t need the use line.

Will whereDate use my created_at index?

Not cleanly. whereDate compiles to DATE(created_at) = ?, which wraps the column in a function and defeats a standard B-tree index on created_at. For high-traffic endpoints, switch to a range: Post::whereBetween('created_at', [today()->startOfDay(), today()->endOfDay()])->get(). It produces a plain BETWEEN clause that the optimizer can serve from an index.

What timezone does Carbon::today() use?

Carbon uses PHP’s default timezone, which Laravel sets from config/app.php‘s timezone key. If that’s 'UTC' but your created_at values are stored in local time (or vice versa), you’ll see rows appear to slip across the day boundary. Either keep both sides UTC or pass a zone-aware constructor: Carbon::today('Asia/Dhaka').

Related guides

  • How to Install Laravel on Ubuntu — bootstrap the Laravel 11 environment.
  • How to Get Current Month Records in Laravel Eloquent — the month-scope counterpart.
  • How to Count Rows in Laravel Eloquent — combine today’s filter with a count.
  • How to Check if a Record Exists in Laravel — the lightweight existence check.

References

Official Laravel query builder docs (whereDate, whereBetween): laravel.com/docs/queries.

TAGGED:EloquentLaravelmysqlphp

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Laravel Eloquent current month records — calendar and query builder illustration How to Get Current Month Records in Laravel Eloquent
Next Article Laravel last inserted ID — Eloquent save populates model primary key illustration How to Retrieve the Last Inserted ID in Laravel Eloquent
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Laravel unknown column CONCAT fix — DB::raw and selectRaw bypass identifier escaping
Web Development

How to Fix “Unknown column ‘CONCAT'” in Laravel

8 Min Read
Laravel request inputs with prefix — filter request()->all() by Str::startsWith
Web Development

How to Retrieve Inputs with a Specific Prefix in Laravel Request

7 Min Read
WordPress get current category ID — three methods by page context
Web Development

How to Get the Current Category ID in WordPress

7 Min Read
Capitalize all words in JavaScript with a ucwords-style function
Web Development

Capitalize All Words in JavaScript (ucwords Equivalent) + First Letter Uppercase

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?