Search code examples
phpphp-carbon

How to format Carbon date as "5th Oct 2017" in PHP?


I use carbon for date processing. I try to formate the date with human understandable format.

My Standard Input :

$date ="05-10-2017";
echo Carbon::parse($date)->format('d m Y);

This format return :

05 Oct 2017

But i want the number formation like,

2nd, 3rd, 4th....

So my expected formation is,

05th Oct 2017

Is this possible ?

Any Suggestions ?


Solution

  • Take a look at http://php.net/manual/en/function.date.php

    There is a table with available formats.

    echo Carbon::parse($date)->format('dS M Y'); //05th Oct 2017
    echo Carbon::parse($date)->format('jS M Y'); //5th Oct 2017