• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Format date with 5th, 3rd etc....

For a blog i'm putting together I use the code below to format the date.

I would like to ad 'st', 'rd', 'nd' though after the number. So currently where the date displays as 1 january 2012 I want it to be 1st January 2012.

Any ideas how to do this?


$formattedDate = date('j M Y', strtotime($row_Recordset1['eventdate']));
0
BrighteyesDesign
Asked:
BrighteyesDesign
1 Solution
 
lwadwellCommented:
use "S" e.g.

echo date_format(new DateTime("2012/08/01"), 'jS F Y'), PHP_EOL;
echo date_format(new DateTime("2012/08/02"), 'jS F Y'), PHP_EOL;
echo date_format(new DateTime("2012/08/03"), 'jS F Y'), PHP_EOL;
echo date_format(new DateTime("2012/08/20"), 'jS F Y'), PHP_EOL;

another example:

echo date('jS F Y', mktime(0, 0, 0, 8, 1, 2012)), PHP_EOL;
echo date('jS F Y', mktime(0, 0, 0, 8, 2, 2012)), PHP_EOL;
echo date('jS F Y', mktime(0, 0, 0, 8, 3, 2012)), PHP_EOL;
echo date('jS F Y', mktime(0, 0, 0, 8, 20, 2012)), PHP_EOL;
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now