UNIXTIME conversion

admin

Administrator
Staff member
For a little project I'm doing, I'm making a news script. In essence, like the area at the bottom of each of these pages, to the admin. The admin type in their subject and news item, as well as the section of the site they want it to appear in. All this gets added to the database as well as their username and a datestamp.
To the user, three news items will appear at a time, starting with the most recent. Pretty straightforward.
I've gotten it to convert from Unix time to a MySQL timestamp, so that's not the problem. The problem's getting it back out.

I've been using UNIX_TIMESTAMP, or at least, trying to. I /think/ I have the wrong syntax. The only help I can find is "use UNIX_TIMESTAMP if you want to do that."

Anyhow, here's what I've got for the main page (hence the "main" part). There's an opening and closing tag for a table surrounding this PHP:
<pre>

$newsresult = mysql_db_query("db_name","SELECT username,UNIX_TIMESTAMP(date)+0,subject,news FROM news WHERE FIND_IN_SET('main',section)>0 ORDER BY date DESC LIMIT 3");

while ($row = mysql_fetch_array($newsresult)) {
$datestr= date("M jS, Y, g:i:sa T",$row["date"]);
echo "<tr>
<td bgcolor=\"#222222\"><font size=+1>".$row["subject"]."</font>
- <font size=-1><a href=http://www.phpbuilder.com/board/archive/index.php/\"/bio/index.php?uname=".$row["username"]."\">".$row["username"]."</a> on $datestr</td>";
echo "</tr><tr>
<td bgcolor=\"#222222\">&nbsp; &nbsp;".$row["news"]."</td>
</tr>
<tr><td>&nbsp;</td></tr>";
}

</pre>

That username stuff makes the name of the poster into a link to their bio.

Anyhow, when $datestr loads, it always displays as Dec 31st, 1969, 6:00:00pm CST. Taking time zones into account, I believe that makes it the beginning of 1970. So obviously, something's going wrong.

Help! And thanks in advance.

-Ian
 
Back
Top