Jump to content


Photo

Really Simple Date Question


  • Please log in to reply
2 replies to this topic

#1 Mateobus

Mateobus
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 24 April 2006 - 09:27 PM

OK, i have a mySQL table with date elements in the format YYYY-MM-DD. How do I display these dates nicely in PHP Like:

Month Day, Year, or just Month, Day

I looked for a couple tutorials but didn't find much. I feel like there should be a really simple way to do this.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 April 2006 - 10:04 PM

if $row['datecol'] is the column from your table and contains today's date, then

echo date ('M jS, Y', strtotime($row['datecol']));

--> Apr 24th, 2006
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 PWD

PWD
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 24 April 2006 - 11:25 PM

You can also do it at your query level as well:

$query= "Select DATE_FORMAT(date_date,'%M %D %Y') AS sortdate from your_table ORDER BY date_date ASC"; /* ORDER BY function orders ascending (ASC) or descending(DESC) */

echo $sortdate;

Also, search the MySQL site for the different formats you can use for DATE_FORMAT()...

[!--fonto:Geneva--][span style="font-family:Geneva"][!--/fonto--]My Gratitude---[!--fontc--][/span][!--/fontc--]
(My gratitude in advance for helping me learn; so I may one day give as freely as you have here today)
----------
[!--sizeo:5--][span style="font-size:18pt;line-height:100%"][!--/sizeo--][!--fonto:Optima--][span style="font-family:Optima"][!--/fonto--][!--coloro:red--][span style="color:red"][!--/coloro--]PWD[!--sizec--][/span][!--/sizec--][!--colorc--][/span][!--/colorc--][!--fontc--][/span][!--/fontc--]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users