Reputation: 225
So if I use:
<?php echo date_format($date, "j M Y") ?>
I get a date in the following format: 5 Jan 1950.
However, what I want is something along the lines of: 5th Jan 1950
How would I go about adding the extra th?
Upvotes: 6
Views: 11409
Reputation: 64695
Look at the formats here http://www.php.net/manual/en/function.date.php, but
<?php echo date_format($date, "jS M Y") ?><br>
For international dates, I guess you would do something like:
$ordinal = new NumberFormatter($locale, NumberFormatter::ORDINAL);
$ordinal = $ordinal->format(date_format($date, "j"));
$pattern = "d'{$ordinal}' MMM yyyy";
$dateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $timezone, IntlDateFormatter::GREGORIAN);
$dateFormatter->setPattern($pattern);
$dateFormatter->format($date->getTimestamp());
The above is untested but it seems like it would work.
Upvotes: 20
Reputation: 27914
echo date_format($date, "jS M Y");
Just check the documentation.
Upvotes: 9