1

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

1
  • Please post the column type for date and the type of database you are using Commented Aug 1, 2011 at 18:12

3 Answers 3

6
date('l jS F Y',strtotime($row['date']))
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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']));

3 Comments

+1 for using DateTime. PRO TIP DateTime is a PHP 5 >= 5.3.0 function. It is easy to use, but if you are using an earlier version you'll need to go with the second recipe!
Yea, all of my stuff is on PHP 5.3. I don't normally think about that limitation.
Some enterprise installs of linux don't use 5.3 yet. Just something to keep in mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.