To change a date format in Laravel 13, call format() on a Carbon instance, for example $post->created_at->format('d M Y'). Eloquent returns date columns as Carbon objects, so no extra parsing is needed. For strings, wrap the value in Carbon::parse() or Carbon::createFromFormat() first.
This guide targets Laravel 13 on PHP 8.3 to 8.5. Carbon ships with Laravel. The examples were written for this article and not executed in a live project.
How do you format an Eloquent date in a controller or Blade view?
Columns such as created_at and updated_at are cast to Carbon automatically. Call format() with a PHP date format string.
$post = App\Models\Post::first();
$post->created_at->format('Y-m-d'); // 2026-11-10
$post->created_at->format('d/m/Y H:i'); // 10/11/2026 09:30
$post->created_at->format('F j, Y'); // November 10, 2026
$post->created_at->format('D, d M Y'); // Tue, 10 Nov 2026In Blade, use the same call: {{ $post->created_at->format('d M Y') }}. Remember that a nullable column such as published_at can be null, so use the nullsafe operator: {{ $post->published_at?->format('d M Y') }}.
Which format characters do you need most?
Yfour-digit year,ytwo-digit yearmmonth with leading zero,nwithout,Mshort name,Ffull namedday with leading zero,jwithoutH24-hour,h12-hour,iminutes,sseconds,AAM/PMDshort weekday,lfull weekday
How do you convert a string to another format?
When a value is a plain string, parse it first. Use createFromFormat() when the input format is known and fixed, because parse() guesses.
use Illuminate\Support\Carbon;
Carbon::parse('2026-11-10 14:05:00')->format('d M Y, h:i A');
// 10 Nov 2026, 02:05 PM
Carbon::createFromFormat('d/m/Y', '25/12/2026')->format('Y-m-d');
// 2026-12-25A value like 03/04/2026 is ambiguous for parse(): it may read it as March 4. Use createFromFormat() for user-entered dates.
How do you change the format for every model automatically?
Use a date cast with a format in the model so the attribute serialises the way you want, for example in JSON responses.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
protected function casts(): array
{
return [
'starts_at' => 'datetime:Y-m-d H:i',
'birthday' => 'date:d/m/Y',
];
}
}The cast format applies when the model is converted to an array or JSON. Reading $event->starts_at still returns a Carbon object that you can format any way you like.
How do you create a custom accessor for a formatted date?
use Illuminate\Database\Eloquent\Casts\Attribute;
protected function startsAtLabel(): Attribute
{
return Attribute::get(
fn () => $this->starts_at?->format('D, d M Y')
);
}Now {{ $event->starts_at_label }} works in Blade, and you change the format in one place.
How do you show relative time and time zones?
$post->created_at->diffForHumans(); // 3 hours ago
$post->created_at->timezone('Asia/Karachi')->format('d M Y H:i');
$post->created_at->isoFormat('LLLL'); // localised long dateLaravel stores times in the timezone set in config/app.php (UTC by default). A common pattern is to keep UTC in the database and convert to the user's timezone only when displaying.
How do you filter by a formatted date in a query?
Do not format in SQL when you can compare dates directly. Use whereDate(), whereMonth() and whereYear().
Post::whereDate('created_at', '2026-11-10')->get();
Post::whereMonth('created_at', 11)->whereYear('created_at', 2026)->get();
Post::whereBetween('created_at', [now()->startOfMonth(), now()->endOfMonth()])->get();For heavy tables, whereBetween on the raw column can use an index, while wrapping the column in a function often cannot.
Common mistakes
- Calling
format()on a string. That throws "Call to a member function format() on string". Parse it first or add the column to the casts. - Calling it on null. Use
?->for nullable dates. - Mixing up
mandi.mis month,iis minutes. - Using
HwithA. Useh(12-hour) with AM/PM. - Storing formatted dates in the database. Store real date columns and format on output.
- Assuming user timezone. Converting twice shifts the time by hours.
How do you verify the format?
- Open
php artisan tinker. - Run
now()->format('d M Y, h:i A')and compare with the current time. - Check an Eloquent date:
App\Models\User::first()->created_at->format('Y-m-d'). - For tests, freeze time with
$this->travelTo(now()->setDate(2026, 11, 10))and assert the exact string.
FAQ
Is Carbon included in Laravel?
Yes. Laravel depends on Carbon, and the now() and today() helpers return Carbon instances.
What is the difference between parse and createFromFormat?
parse guesses the format; createFromFormat uses the exact format you give it and is safer for user input.
How do I change the default date format for JSON?
Use a model cast such as datetime:Y-m-d H:i, or override serializeDate() in the model.



