Gerry
Gerry

Reputation: 21

PHP How to change date format from variable

im currently pulling data from my database along with a date via variable. The code im using is this

echo "".$row["firstname"]." ".$row["lastname"]." thinks that it will happen on ".$row["date"]."";

the results are being displayed as : bobby anderson thinks that it will happen on 2011-09-15

but id like the date to be displayed as Monday 1st August 2011

Upvotes: 1

Views: 5426

Answers (3)

cwallenpoole
cwallenpoole

Reputation: 82058

You can either use date along with strtotime, or you can use the date_create_from_format method (date_create_from_format example):

echo DateTime::createFromFormat( "Y-n-j", $row['date'])
     ->format( 'l jS F Y' );

(an now strtotime)

echo date('l jS F Y',strtotime($row['date']));

Upvotes: 1

Christian Mann
Christian Mann

Reputation: 8125

Take a look at the date function, along with strtotime.

Upvotes: 1

RiaD
RiaD

Reputation: 47650

date('l jS F Y',strtotime($row['date']))

Upvotes: 6

Related Questions