How to format date dd-mmm-yyy in laravel?

by cali_green , in category: PHP Frameworks , 8 months ago

How to format date dd-mmm-yyy in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 4 months ago

@cali_green 

To format a date in Laravel using the dd-mmm-yyy format (e.g. 01-Jan-2022), you can use the following code:

1
2
3
4
5
$date = CarbonCarbon::now(); // Get the current date

$formattedDate = $date->format('d-M-Y');

echo $formattedDate; // Output: 01-Jan-2022


In this code snippet, we first get the current date using the Carbon library, which is included in Laravel by default. We then format the date using the format() method with the 'd-M-Y' format string, which will output the date in the dd-mmm-yyy format.