Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GobsRuiz's avatar

How do I register the system date?

I'm making a news crud and I want to show the date that this news was registered. Laravel already has timestamps ready, but he also takes the time and I would just like the date. How do I do?

0 likes
4 replies
ollie_123's avatar

In your model make sure you use protected $dates = ['registered_at'];. Then in your blade file you can grab the date from the array and format it such as $news->registered_at->format('d/m/y');

GobsRuiz's avatar

I did it that way

   $created = new DateTime();
   $news->date = $created->format('d/m/y');

But in the database it saves with this format ('y / m / d')

tykus's avatar

Bank, do you mean database table?

Your database date column type will have Y-m-d format, you can modify how this is displayed in your view layer. As @ollie_123 mentioned, you can cast fields on the model to Carbon instances, and use the format method to render them however you please.

Please or to participate in this conversation.