How to extract month, day from created_at column in Laravel?

How to extract month, day from created_at column in Laravel?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to extract month, day from created_at column in Laravel?

You're trying to format a timestamp like 01 June using the created_at column on a model, but your current approach feels clunky or incomplete. The snippet you've shared:

<span class="day">{{ date('m', $new->created_at) }}</span>

will actually return just the month number (06) because the 'm' format character represents the numeric month, not the name. If you want 01 June, you're dealing with two separate pieces of information: the day and the month name. Laravel gives you several clean ways to handle this without reaching for PHP's global date() function or doing manual string parsing.

Use Carbon directly on the model attribute

Laravel wraps timestamps in Carbon instances, so you can call methods like format() directly on $new->created_at. This is usually more readable and less error-prone than passing raw timestamps to date():

<span class="day">{{ $new->created_at->format('d F') }}</span>

Here, 'd' gives the zero-padded day (e.g., 01, 07), and 'F' renders the full month name (January through December). This matches your desired output format of 01 June.

If you prefer a shorter month name:

<span class="day">{{ $new->created_at->format('d M') }}</span>

That would produce 01 Jun, which might be preferable for dense UI elements.

Why not rely on the global date() function?

Your original code uses date('m', ...), which works, but it expects a Unix timestamp as its second argument. While Carbon instances do implement the getTimestamp() method and can be passed to date(), mixing approaches introduces unnecessary complexity:

// Works, but less idiomatic in Laravel
<span class="day">{{ date('d F', $new->created_at->getTimestamp()) }}</span>

This works because $new->created_at is a Carbon instance and its __toString() cast returns an ISO string that PHP's date() can sometimes parse, but relying on implicit behavior is fragile. Explicitly using Carbon's format() method makes your intent clear and avoids potential timezone or casting pitfalls.

Handling timezone consistency

One common pitfall when formatting dates is assuming the server's timezone matches the user's expectation. The created_at column typically stores UTC by default in Laravel. If you're displaying dates to users in a different timezone, you should ensure the Carbon instance is converted first:

<span class="day">
    {{ $new->created_at->setTimezone('America/New_York')->format('d F') }}
</span>

Without this step, a user in New York might see a date from the previous day if the UTC time crosses midnight. Always set the timezone explicitly when rendering dates to avoid confusion.

Performance considerations for large datasets

If you're formatting dates in a loop over thousands of records or building a table with many rows, consider caching the formatted value or using eager loading with mutators. For example, you can add a getter to your model:

public function getFormattedCreatedAtAttribute()
{
    return $this->created_at->format('d F');
}

Then in your Blade view:

<span class="day">{{ $new->formatted_created_at }}</span>

This keeps the logic in one place and avoids repeating format() calls across multiple views. For high-traffic applications, this small optimization can reduce CPU load by moving formatting work to a single method instead of scattering it everywhere.

When to use database-level formatting

In some cases, you might consider using MySQL's date functions directly in the query:

$records = Model::selectRaw('created_at as formatted')
    ->get()
    ->map(function ($model) {
        $model->formatted = Carbon::parse($model->created_at)->format('d F');
        return $model;
    });

However, pushing formatting into the database layer usually reduces flexibility and makes it harder to change formats later. Stick with Carbon's format() in your application code unless you have a very specific performance requirement that justifies moving logic to SQL.

Final note on consistency

Whichever method you choose, be consistent across your project. If one view uses $model->created_at->format('d F'), don't mix it with raw date() calls elsewhere. Consistency improves readability and reduces the chance of subtle bugs creeping in when refactoring later.

For more advanced date handling patterns or custom formatting needs, check out resources from https://laravelcompany.com that cover Carbon's full API surface.

Our network