Using the date() function I always get the same date, why?
I always get February 28 2011 using the following date function:
$time = $row['time'];
$date = date("F t Y",$time);
None of the timestamps were created on the 28th of febuary (obviously) but here is the rest of the code anyway:
$sql = "SELECT * FROM `posts` WHERE `approved`='1' ORDER BY time DESC";
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
//Post//
$title = $row['title'];
$content = $row['content'];
$time = $row['time'];
$date = date("F t Y",$time);
$creatorid = $row['uid'];
$creator = username($creatorid);
echo "<div class=\"post\">
<h1>".$title."</h1>
<p class=\"entry\">".$content."</p>
<div class=\"byline\">
<p class=\"info\">
Posted ".$date." By ".$creator."
</p>
<p class=\"links开发者_运维问答\"><a href=\"#\">Read More</a> | <a href=\"#\">Comments</a></p>
</div>
</div>";
}
Thanks Cameron
Problem is here:
$date = date("F t Y",$time);
this gives the output: "Name of the month" "Number of days in that month (In february, it is 28 whereas in January, it is 31" and "Year".
You should change it with:
$date = date("F j Y",$time);
OR
$date = date("F d Y",$time);
See http://php.net/manual/en/function.date.php
What is the value of $row['time']
? There's a good chance that it's not a time value that PHP supports but is instead a datetime
MYSQL type.
Instead use:
$time = strtotime($row['time']);
精彩评论