How to Change Date Format in Laravel 12

In this post, I’ll show you how to change date formats in Laravel 12. Whether you're displaying a date in Blade, formatting it in a controller, or working with Carbon, I'll walk you through each method step by step. It's simple, clean, and beginner-friendly.

When working with dates in Laravel, you’ll often need to change the format — for example, from 2025-04-05 to 05 April, 2025. Laravel makes it easy with built-in tools like Carbon and Eloquent.

How to Change Date Format in Laravel 12

How to Change Date Format in Laravel 12

 

Using Carbon in Controller

Carbon is already included in Laravel. You can use it like this in your controller.

use Carbon\Carbon;

public function showDate()
{
    $originalDate = '2025-04-05';
    $formattedDate = Carbon::parse($originalDate)->format('d M Y');
    
    return $formattedDate; // Output: 05 Apr 2025
}

More Formats:

Carbon::parse($originalDate)->format('d-m-Y'); // 05-04-2025
Carbon::parse($originalDate)->format('F j, Y'); // April 5, 2025
Carbon::parse($originalDate)->format('Y/m/d'); // 2025/04/05

 

Formatting Dates from Eloquent Models

If you have a model with a created_at or updated_at field, format it like this:

$post = Post::find(1);
$formatted = $post->created_at->format('d M Y'); 

echo $formatted; // 05 Apr 2025

 

Formatting Dates in Blade Views

You can format a model’s date directly in your Blade file:

<p>{{ $post->created_at ? $post->created_at->format('d M Y') : '-' }}</p>

 

Custom Date Accessor in Model

If you want to format the date every time, create an accessor in your model:

// In Post.php model
public function getFormattedDateAttribute()
{
    return $this->created_at->format('d M Y');
}

Then in your Blade:

<p>{{ $post->formatted_date }}</p>

 

Convert Current Date in Laravel

Want to format today’s date:

$today = Carbon::now()->format('l, d F Y'); // Output: Saturday, 05 April 2025

 

Common Date Format Options

Here is your common date format.

Format Output Example
d-m-Y 05-04-2025
Y-m-d 2025-04-05
d M Y 05 Apr 2025
F j, Y April 5, 2025
l, d F Y Saturday, 05 April 2025

 


You might also like:

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS