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
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.
select DATE_FORMAT('1997-10-04 22:23:00', '% %M %Y');
-> 'Saturday October 1997'
August 2nd, 2000, 09:36 AM
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.
August 2nd, 2000, 12:13 PM
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");
August 3rd, 2000, 09:49 AM
The problem i was having was that I just needed to do a mysql_fetch_row to get the result from mysql select date_format command since it returns the result as an array with 1 row