0

I get the data from database to html page as

 <?php $subscriber = json_decode($this->subscriber); ?> 

I am displaying all the elements as

 <?php echo $subscriber->date; ?> 

Where as now I want to display the date. When I directly display the date I am getting the format as 2014-07-15 17:02:50

But I want to display in the format 15-07-2014. What are the functions used and how the code should be written in php?

2 Answers 2

3

by using date() function

date('d-m-y',strtotime( $subscriber->date)) 
Sign up to request clarification or add additional context in comments.

Comments

1

Use PHPs DateTime class to do it the OO way:

$dt = new DateTime($subscriber->date); echo $dt->format('d-m-Y'); 

Or you can convert the date first from string to a unix timestamp using strtotime() and then format it with the date() function as Vijayaragavendran mentioned in his answer:

echo date('d-m-Y',strtotime( $subscriber->date)); 

1 Comment

Lol looks like you made a similar typo in your update... y :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.