View Full Version : MySQL timestamp
cursor_joe
04-27-2005, 07:15 AM
...ok i've read that in MySQL 4.1, you can view the timestamp in MySQL as the UNIX by adding 0 to the end of the row. Can someone help me modify my code so that this same idea will also in my code?
<tr><td colspan="2">
<?php $datetime=$row["time" + 0];
$year = substr( $datetime, 0,4 );
$mon = substr( $datetime, 5,2 );
$day = substr( $datetime, 7,2 );
$hour = substr( $datetime, 9,2 );
$min = substr( $datetime, 11,2 );
$sec = substr( $datetime, 13,2);
$orgdate = date("l F dS, Y h:i A",
mktime( $hour, $min, $sec, $mon, $day, $year));
?>
<b>Date:</b> <?php echo $datetime; ?></td></tr>
Tangerine Dream
04-27-2005, 05:36 PM
Hi, in fact, your code doesn't contain any SQL queries. Suppose you have a 'time' column that contains timestamp values, then:
$sql = "SELECT 0+time AS time FROM yourtable";
// run the query, fetch rows
cursor_joe
04-27-2005, 11:21 PM
sorry... this is my whole code. Where would i add that in?:)
<html><head><title>View My Blogs!!!</title></head>
<body>
<?php
$rs = @mysql_connect( "localhost",name,pass);
$rs = @mysql_select_db("blog");
#SQL query for entries in descinding time order
$sql =
"select * from post order by time desc";
$rs = @mysql_query($sql);
#loop through records writing a table for each one
while ( $row = mysql_fetch_array($rs))
{
?>
<table border="0" width="375">
<tr><td colspan="2">
<?php $datetime=$row["time"];
$year = substr( $datetime, 0,4 );
$mon = substr( $datetime, 5,2 );
$day = substr( $datetime, 7,2 );
$hour = substr( $datetime, 9,2 );
$min = substr( $datetime, 11,2 );
$sec = substr( $datetime, 13,2);
$orgdate = date("l F dS, Y h:i A",
mktime( $hour, $min, $sec, $mon, $day, $year));
?>
<b>Date:</b> <?php echo $datetime; ?></td></tr>
<tr>
<td><b>Title: </b></td><td><marquee direction="left" behavior="alternate"><font color="blue" size="4"><?php echo $row["title"]; ?></font></marquee</td></tr>
<tr><td colspan="2"><b><font color="red">Blogging</font>:</b><br>
<?php echo $row["blog"]; ?><td></tr>
</table>
<br>
<hr><br>
<?php } ?>
</body></html>
Tangerine Dream
04-30-2005, 09:47 PM
If you want 'time', 'title', 'blog' columns in result set and time column is TIMESTAMP:
#SQL query for entries in descinding time order
$sql =
"select 0+time as time, title, blog from post order by time desc";
$rs = @mysql_query($sql);
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.