Mr.Happy
Mr.Happy

Reputation: 2647

php convert timestamp to specific format

I have one field registered_date which is timestamp type in MYSQL. Now I an new with php I need your help.

I am getting this result: 2014-06-19 15:59:49

and I want this output: 19 June 2014 15:59 PM

Note: I am storing timestamp in php variable from sql query.

Any Idea?

Upvotes: 0

Views: 69

Answers (2)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

Since you tagged the question with mysql here is the mysql solution, you can use date_format() function while selecting the data and you will have desired format.

mysql> select date_format('2014-06-19 15:59:49','%d %M %Y %H:%i %p') as date ;
+-----------------------+
| date                  |
+-----------------------+
| 19 June 2014 15:59 PM |
+-----------------------+
1 row in set (0.00 sec)

Upvotes: 1

mleko
mleko

Reputation: 12233

http://php.net/manual/en/function.strtotime.php
http://php.net/manual/pl/function.date.php

$date = date('D M Y H:i A', strtotime($timestamp));

Upvotes: 1

Related Questions