#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    24
    Rep Power
    0
    Hi,

    I am using a mySQL database to retreive date information and i am not sure how to format this information in php to a differnt format. Ive looked @ the date function in php but that only seems to work with the currnet local date and the date_format function in sql only seems to work in mySQL and not thru php.

    Any help would be appreciated

    CMatrix
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    20
    Rep Power
    0
    Look in the online mysql documentation, section 7.4.11. It will explain how mysql can format a date field into almost any desired format.

    exp.

    select DATE_FORMAT('1997-10-04 22:23:00', '% %M %Y');

    -> 'Saturday October 1997'

    later
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    1
    Rep Power
    0
    You didn't answer his question.
    I'm having the same problem btw.

    How do you get a MySQL date formated in PHP? I need to get it from yyyy-mm-dd to: mm/dd/yy.

    I can do it from the MySQL command line interactively, but there seems to be no PHP API function for this. PHP also only seems to work with local dates through the date function. I am a PHP/MySQL novice, and I'm finding it hard to find an example to study.
  6. #4
  7. 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
    19
    If you can manipulate mysql dates on the command line, then you know how to manipulate them in php. Just send the appropriate select statement via mysql_query().

    $result=mysql_query("select some,fields,date_format('format string',datefield) as fdate from table");

    If you really want to manipulate the date format in php then you'll need to retrieve the date as a unixtimestamp.

    $result=mysql_query("select unix_timestamp(datefield) as utstmp from table");
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    24
    Rep Power
    0
    The problem i was having was that I just needed to do a mysql_fetch_row[0] to get the result from mysql select date_format command since it returns the result as an array with 1 row

    cmatrix

IMN logo majestic logo threadwatch logo seochat tools logo