How to format a date in a laravel blade?

Member

by samara , in category: PHP CMS , 7 months ago

How to format a date in a laravel blade?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elisha_langworth , 7 months ago

@samara 

To format a date in a Laravel Blade view, you can use the Carbon class which is included in Laravel by default. Here's an example of how you can format a date in a Blade view:

1
2
{{-- Assuming $date is a variable containing the date --}}
{{ CarbonCarbon::parse($date)->format('d/m/Y') }}


In this example, CarbonCarbon::parse($date) is used to convert the date to a Carbon instance, and then the format() method is used to specify the desired date format. In this case, 'd/m/Y' is used to format the date as day/month/year.


You can use any valid date format supported by the Carbon library. Refer to the official Carbon documentation for more information on date formatting options: https://carbon.nesbot.com/docs/#api-formatting