Strftime日期改变与PHP和Mysql

时间:2013-06-03 21:21:38

标签: php mysql strtotime

<?php
    //run a select query to my latest 1 item
    include "storescripts/connect_to_mysql.php";
    // This block grabs the whole list for viewing
$dynamicList= "";
$sql = mysql_query("SELECT * FROM blog");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
    while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
             $title = $row["title"];
             $author = $row["author"];
             $category = $row["category"];
             $article = $row["article"];
            // $postdate = strftime("%b %d, %Y", strtotime($row["postdate"]));
              $postdate = $row["postdate"];
             //Seperate so it's easier to see what i'm working with here.
             $short = substr(strip_tags($article), 0, 400);

             $dynamicList .= '<ul>
<li>
<div class="wrapFirstRowBlog">
    <div class="postDate">'.$postdate.'</div>
    <div class="nextToDate">
    <div class="blogTitle"><h3><a href="blog.php?id='.$id.'">'.$title.'</a></h3></div>
    <div class="author">written by '.$author.' for the '.$category.' section.</div>
    <div class="socialNetwork"></div>
    </div>
</div>
<div class="blogPreview">
<img class="blogLeft" src="../blog_images/'.$id.'.jpg" width="150" height"150" alt="'.$title.'"/>'.$short.'...<a href="http://www.moniquetrinidadjewelry.com/images/new-images/read-more.png"><img src="http://www.moniquetrinidadjewelry.com/images/new-images/read-more.png" alt="read more of this post" /></a>
</div>
</li>
</ul>';
    }
} else {
    $dynamicList = 'Nothing posted yet...check back soon!';
}
mysql_close();
?>

我尝试过在这里到处搜索的许多组合,我可以在我的脚本中开始我正在尝试做的事情。我正在尝试将日期转换为仅显示日期。我的mysql阅读是

2013-06-03 00:18:32 

我想简单地说明只显示日期而不是时间。在我的脚本中,我似乎无法弄清楚如何做到这一点。我试过了

$postdate = strftime("%b %d, %Y", strtotime($row["postdate"]));

这是行的包含,无法弄明白。我应该在什么时候输出这些更改以及任何有关为什么会受到高度赞赏的参考。

1 个答案:

答案 0 :(得分:2)

我认为您可以使用date功能

$postdate = date("m d, Y", strtotime($row["postdate"]));

这将在您的变量$postdate中存储您的日期

06 03, 2013

LIVE DEMO