FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
MySQL / PHP Date formating
Message  

Reply with quote
Post MySQL / PHP Date formating 
I have Dates stored in my MySQL Database That when I display them on a .php  page I want them to be displayed in a different format.

Currently they are in
Year-month-day

I want them to be
day of the week abriv.(Tue) - month abriv.(Apr) - number day with suffic(1st)


_________________
Sarah Atkinson
View user's profile Send private message Send e-mail

Reply with quote
Post  
I figured it out

Code:

$result = @mysql_query("SELECT id, , DATE_FORMAT(day, '%a %b, %D') as date_string FROM $fromwhere WHERE day>$x");

while ($row = mysql_fetch_array($result)) {
      $dbdate=$row["date_string"];
      echo '<tr><td>' . $dbdate . '</td>';
}
[/code]


_________________
Sarah Atkinson
View user's profile Send private message Send e-mail

Reply with quote
Post  
Good job with figureing this out. Its also helpful to many other people who aren't really sure how to do this, if you post exactly how you figured out the solution. I know you posted the code, but some may not be able to tell by looking at the code.

View user's profile Send private message

Reply with quote
Post  
Its quite simple really, I'll explain Sarah's SQL a bit:

Code:

"SELECT id, DATE_FORMAT(day, '%a %b, %D') as date_string FROM $fromwhere WHERE day>$x");


First off she selects the fields 'id' and the "date" by using the date_format() function which is sort of like sprintf() the php function except for its own uses %a being Day(abriv) -- %b being Month(abriv) and %D being day number with suffix.  Then she selects the return value of the date_format() function AS date_string.  Then she also limits her query down based on if day > var $x.

Hope this helps to explain it a bit more.


_________________
Software Engineer
http://www.tuxmafia.com
View user's profile Send private message Visit poster's website
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com