Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date conversion dd [th/st/rd] / month / yyyy

Tags:

date

php

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

like image 494
Aliya Kcx Avatar asked Nov 30 '12 07:11

Aliya Kcx


2 Answers

You can use S letter as following:

$new_date = date('jS F Y', strtotime($user_date)); 

Check manual.

like image 52
hsz Avatar answered Sep 23 '22 09:09

hsz


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 
like image 31
PHP Ferrari Avatar answered Sep 22 '22 09:09

PHP Ferrari