Jump to content


Photo

Data Format


  • Please log in to reply
4 replies to this topic

#1 barney0o0

barney0o0
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts

Posted 09 March 2006 - 08:47 AM

Sorry, i know its been discussed on numerous occasions in the forums, but my head hurts for the simpliest of things.....

How do i change the code below to change the format from 2002-12-27 (database format) to 27 December 2002(pulled down display format)?

SELECT eventTITLE, eventDATE
FROM events
ORDER BY eventDATE ASC


...or would it be more efficant to change the format in php prior to pulling down the results?

Thanks in advance

#2 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 09 March 2006 - 09:06 AM

[!--quoteo(post=353184:date=Mar 9 2006, 08:47 AM:name=barney0o0)--][div class=\'quotetop\']QUOTE(barney0o0 @ Mar 9 2006, 08:47 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Sorry, i know its been discussed on numerous occasions in the forums, but my head hurts for the simpliest of things.....

How do i change the code below to change the format from 2002-12-27 (database format) to 27 December 2002(pulled down display format)?

SELECT eventTITLE, eventDATE
FROM events
ORDER BY eventDATE ASC
...or would it be more efficant to change the format in php prior to pulling down the results?

Thanks in advance
[/quote]

I prefer to manipulate my date formats with PHP.

$query = mysql_query("SELECT eventTITLE, eventDATE FROM events ORDER BY eventDATE ASC");
if ($row = mysql_fetch_assoc($query))
{
   do 
   {
      $date = date("d/m/Y", strtotime($row["eventDATE"]));
   } 
   while ($row = mysql_fetch_assoc($query));
}


call me a safe bet, i'm betting i'm not

#3 barney0o0

barney0o0
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts

Posted 09 March 2006 - 04:06 PM

Cheers lessthan for your response....I had i play with your sugesstion, but as im using dreamweavers behaviours to display the pulled down data i got in a bit of a mess....

Ive now played and searched around and come up with:

SELECT DATE_FORMAT(eventdate2, '%D/%M/%Y') AS eventdate2, eventTITLE,paratext
FROM events
ORDER BY eventdate2

that produces

7th/February/2006
Music night2
Intro text

Is there a way to remove the forward slashes and replace with a space?

many thanks

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 March 2006 - 05:51 PM

[!--quoteo(post=353290:date=Mar 9 2006, 11:06 AM:name=barney0o0)--][div class=\'quotetop\']QUOTE(barney0o0 @ Mar 9 2006, 11:06 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Is there a way to remove the forward slashes and replace with a space?

many thanks
[/quote]

sure, just adjust your DATE_FORMAT function:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] DATE_FORMAT(eventdate2, '%D %M %Y') AS eventdate2, eventTITLE,paratext
FROM events ORDER BY eventdate2
[!--sql2--][/div][!--sql3--]
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 barney0o0

barney0o0
  • Members
  • PipPipPip
  • Advanced Member
  • 103 posts

Posted 09 March 2006 - 09:17 PM

As per usual, things seem so so easy when theyre spelt out...

many thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users