October 22nd, 2000, 04:10 PM
I'm having a lot of difficulty with formating a date field from a MySQL datebase in PHP. I've tried mysql's "select date_format". I've also tried to use php's date(time,"M d, Y"), but I either get a date from 2038 or 1969. The date format in the mysql datebase is timestamp(14). Any code on displaying this data type in php would be greatly appreciated.
October 22nd, 2000, 06:57 PM
make your mySQL table date an INT(11) column. It'll put the UNIX time stamp in. When you pull it out of the database, format it using the PHP date() function.
something like this....
$query = mysql_query("SELECT date FROM blah;");
$fetch = mysql_fetch_row($query);
$date = date('m/j/Y', $fetch);
find the letters to format the date function somewhere in the php.net documentation
[This message has been edited by Atticus (edited October 22, 2000).]
October 22nd, 2000, 07:55 PM
Stick with mysql's date and time datatypes over unix types, UNLESS you have to do a lot of juggling with the data or need to have it in several different formats.
What problems are you having with the date_format function? How are you trying to use it?
October 22nd, 2000, 11:31 PM
Are you sure the data is being put into mysql correctly? Can you show us the syntax of the sql statement involving date_format your using and how you're putting the date into the database? It's better to use the mysql functions that to change everything over to unix timestamps. It just adds a level you don't need to bother with...
[This message has been edited by SepodatiCreations (edited October 22, 2000).]
October 23rd, 2000, 05:40 AM
Stick to timestamp and display it in php with:
"select DATE_FORMAT(column_name, "%Y-%m-%d %H:%i") as time"
echo "$time" and you'll see something like 2000-10-23 11:20.
You might wanna check the letter-synthax on date_format to make fit your needs, but as stated above works for me.