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

by cali_green , in category: PHP Frameworks , a year ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 10 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.

Related Threads:

How to change date format to 'dd-mon-yy' in oracle?
How to convert 'dd-mm-yyyy' to 'dd-mmm-yyyy' in postgresql?
How to format a date in a laravel blade?
How to change the date format in laravel view?
How to change date format in php laravel?
How to convert timestamp to yyyy-mm-dd hh24:mi:ss format in oracle?