Ok, I have a database with the 'time' field stored as the DATETIME format. I have no trouble retreiving this info and outputting it, but it seems to output wrong. I hear the DATETIME format in mySQL is in the format YYYY-MM-DD-HH-MM, yet the php date function uses a UNIX DATESTAMP function. I have tried lots of ways, including using the DATE_FORMAT() function in mySQL, and I still can't get the date right.
I am looking to display the date like follows:
28 February 2002 01:01 PM
and I beleive this looks something like 2002-02-28 13:01:07 in mySQL.
Here is my code so far:
...
$sql = "SELECT * FROM news ORDER BY time DESC";
$result = @($sql,$connection) or die("Couldn't execute query.");
while($row = mysql_fetch_array($result)) {
...
echo date("j F Y h:i A", $row['time']);
}
...
This gives me:
31 December 1969 04:00 PM
Which is not right, so I have some conversion problem. Should I use the DATE_FORMAT function? if so, how exactly would I word it? does PHP have some fucntion to convert the mySQL DATETIME data into UNIX TIMESTAMP format, for use with the date() function?
Thanks,
Neil McGlennon