How to display only the current date in Laravel using Carbon?

I am using Laravel and the Carbon class to get the current date and time.

Carbon::now();

This displays the current date and time like this:

2015-03-10 23:23:46

But I only want to show the date without the time, like this:

2024-10-11

How can I modify my code to display only the date?

To display only the date in Laravel using the Carbon class, you can use the toDateString() method. This will give you just the date without the time.

$date = Carbon::now()->toDateString();

This will return the current date in the format YYYY-MM-DD, like:

2024-10-11

If you need a custom date format, you can also use the format() method. For example, if you want the date in a different format, you can do:

$date = Carbon::now()->format('Y-m-d');

Both methods will display only the date.