Displaying date as text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Displaying date as text

Post by aceconcepts »

Hi,

I have dates stored in a database I have extracted all of them and displayed them on a page.

However, I would like to display the date as a day textually.

How can I do this?

I've tried the following:

Code: Select all

echo date("l", $sessionDate);
but this displays the same day for each in the loop.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

What is the format of $sessionDate ?

It needs to be a timestamp.

So either have mysql pull it out as a timestamp, or convert it.

Code: Select all

echo date('l',strtotime($sessionDate)); // But this still depends how $sessionDate is formated
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

$sessionDate is currently formatted as date (0000-00-00)
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Code: Select all

strtotime(); //will work then
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

thanks for that, it worked perfectly
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Put it on the database to give it to you the way you want it. In MySQL...

Code: Select all

SELECT DATE_FORMAT(`dateField`, '%W') AS date FROM `myTable`;
Post Reply