To format a Carbon date to string output, you can use the format function and pass the following parameter


$carbonDate->format('l jS \\of F Y h:i:s A');

//Output -> Thursday 25th of December 1975 02:15:16 PM

If you are looking to shorten the day and month in this format you can use


$carbonDate->format('D jS \\of M Y h:i:s A');

//Output -> Mon 17th of Oct 2022 06:33:47 AM

If you are looking to output the time in 24 hour time instead of AM/PM you can use following


$carbonDate->format('D jS \\of M Y H:i:s');

//Output -> Mon 17th of Oct 2022 18:33:47
Comments