#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    I am trying to use MySQL DATE_FORMAT to pull a date from a column. I can run the SQL statement in MySQL and it works fine, but when I use the same statement in PHP it returns blank. In fact, it will even return the correct number of lines, printing "Formatted date - " the number of times that the SQL statement is true in the DB.

    Anyone have any clues?


    <?
    mysql_connect("localhost", "root", "passwd");
    $query = "SELECT DATE_FORMAT(date_field, 'd M, Y') FROM table_name WHERE (appno='11910')";
    $result = mysql_db_query("database_name", $query);
    if ($result) {
    while ($r = mysql_fetch_array($result)) {
    $trans_date = $r["trans_date"];
    echo "formatted date - $trans_date</font><br>";
    }
    echo "<br>";

    } else {
    echo "No data.";
    }
    mysql_free_result($result);

    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Sorry all, I screwed up that post, since I already knew the answer. The real question is this:

    How do I include a DATE_FORMAT in a full SQL string, that will print multiple records that all have different dates, since it does not appear that DATE_FORMAT is handled the same way a standard SQL statement is.
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    you need to alias the function results. You are checking for "trans_date" in your result set so use that as your alias.

    select date_format(date_field,'d M, Y') as trans_date from table_name where appno='11910';

Similar Threads

  1. Replies: 5
    Last Post: December 6th, 2004, 03:59 AM
  2. A few Install questions
    By kolatracks in forum Linux Help
    Replies: 2
    Last Post: October 27th, 2003, 02:31 AM
  3. CGI::Session (& a few questions)
    By Stenyjj in forum Perl Programming
    Replies: 6
    Last Post: July 4th, 2003, 02:21 PM
  4. Online news database performance questions
    By zbriu in forum MySQL Help
    Replies: 2
    Last Post: May 8th, 2003, 09:38 PM
  5. Inserting New questions
    By woldie in forum PHP Development
    Replies: 2
    Last Post: May 14th, 2002, 08:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo