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

munazzil's avatar

What is the usage of Carbon?

When we use as like this in laravel controller. What is the purpose and what is the usage og that?

Carbon::now();
0 likes
8 replies
manelgavalda's avatar
Level 50

The purpose of this (Carbon::now()) is to return the current time with a Carbon instance. You can also use the laravel helper now(), so you won't need to import the Carbon class.

And the purpose of Carbon is to make it easy to work with timestamps. For example if you are not working with carbon instances, it will be hard to compare timestamps, extract the day of the timestamp, show how much has passed from the date of the carbon instance in a readable way, etc....

I think the Carbon docs are pretty good in order to see the functionallity and some usage examples: https://carbon.nesbot.com/docs/

2 likes
cmdobueno's avatar

Read the documentation. No one is going to explain how carbon works when it is FULLY documented.

1 like
Dalma's avatar

Do set aside about a half day to read the documentation though as it is VERY thorough.

1 like
jlrdw's avatar

What is the usage of Carbon?

Dating man, dating. Just kidding.

Really helpful to display many date formats, ie diff for humans, etc. But all based on php, like laravel is php but Taylor implemented many shortcuts and helpers to speed up many things.

1 like
jlrdw's avatar

You forgot @snapey I'm sure an honest mistake. I'll take care of it. Thanks Dude.

Ah you edited and added him, good.

1 like

Please or to participate in this conversation.