gaurav malik gaurav malik - 1 month ago 6
PHP Question

Change datetime to date with month name in word

I am new to Stack Overflow. So please guide me if my question is not clear to you.

I have a datetime such as 2016-10-08 11:02:55.
I need to convert it into like this 8 OCT 2016.


Do anybody have any idea how could i get it in this format. This has to be do in PHP.

Thanks.

Answer

You need to use strtotime() to convert target string to time and use date() to convert time to formated date. Also strtoupper() convert all character to uppercase.

$x = "2016-10-08 11:02:55";
echo strtoupper(date("j M Y",strtotime($x)));

Result:

8 OCT 2016 

Working DEMO

Comments