Reputation: 429
I have my users entering the date in this format :- mm/dd/yyyy (11/21/2012)
My PHP script converts the date into the following format :- dd-Month-yyyy (21-November-2012)
I do this using :-
$new_date = date('d-F-Y', strtotime($user_date));
How can I have the date in this format :- 21st November 2012
?
Thanks
Upvotes: 41
Views: 54562
Reputation: 152216
You can use S
letter as following:
$new_date = date('jS F Y', strtotime($user_date));
Check manual.
Upvotes: 92
Reputation: 176
You can use something like:
echo date('l, F jS');
Or even get a bit fancy with the HTML:
echo date('l, F j<\s\u\p>S</\s\u\p>');
Upvotes: 3
Reputation: 101
$new_date = date('jS F Y', strtotime($date));
S
- English ordinal suffix for the day of the month, 2 characters
(st, nd, rd or th. Works well with j)
Upvotes: 10
Reputation: 1091
**My Date = 22-12-1992**
<?php
$mydate = "22-12-1992";
$newDate = date("d M Y", strtotime($mydate));
$new_date = date('dS F Y', strtotime($newDate));
echo $new_date;
?>
**OutPut = 22nd December 1992**
Upvotes: 4
Reputation: 1406
$date = date_create('09-22-2012');
by this code you will get your desire
echo $date->format('d S F Y');
for more you can also visit http://php.net/manual/en/datetime.formats.date.php
Upvotes: 0
Reputation: 15616
It will output as you expect
$my_date = '2016-01-01';
echo date('F jS, Y', strtotime($my_date));
# January 1st, 2016
while dS will also prepends 0
echo date('F dS, Y', strtotime($my_date));
# January 01st, 2016
Upvotes: 23