Skip to main content
Quick Tip

Change Format Of Created_at and Updated_at

Tip given by @syofyanzuhad

To change the format of created_at you can add a method in your model like this:

Since Laravel 9:

protected function createdAtFormatted(): Attribute
{
return Attribute::make(
get: fn ($value, $attributes) => $attributes['created_at']->format('H:i d, M Y'),
);
}

Laravel 8 and below:

public function getCreatedAtFormattedAttribute()
{
return $this->created_at->format('H:i d, M Y');
}

So you can use it $entry->created_at_formatted when it's needed. It will return the created_at attribute like this: 04:19 23, Aug 2020.

And also for changing format of updated_at attribute, you can add this method :

Since Laravel 9:

protected function updatedAtFormatted(): Attribute
{
return Attribute::make(
get: fn ($value, $attributes) => $attributes['updated_at']->format('H:i d, M Y'),
);
}

Laravel 8 and below:

public function getUpdatedAtFormattedAttribute()
{
return $this->updated_at->format('H:i d, M Y');
}

So you can use it $entry->updated_at_formatted when it's needed. It will return the updated_at attribute like this: 04:19 23, Aug 2020.

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

[NEW] Building a Typical Laravel SaaS

10 lessons
1 h 27 min

Laravel Modules and DDD

16 lessons
1 h 59 min

Filament 4 From Scratch

28 lessons
2 h 25 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.