duanshan2988 2016-09-11 22:36
浏览 81
已采纳

如何从php中的phpmyadmin获取日期(d,m,y)? [重复]

This question already has an answer here:

I want to fetch date format from (y,m,d) to (d,m,y).In my database I already insert data like date and images so many around 400 images.I dun want to insert again.phpmyadmin

The following is to fetch from database.

  1. <?
  2. $sql = "SELECT * FROM ShowFillter GROUP BY Image_Date order by Image_Date desc";
  3. $objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
  4. while($objResult1 = mysql_fetch_array($objQuery))
  5. {
  6. ?>
  7. <li class="filter" data-filter="<?=$objResult1['Image_Date'];?>">
  8. <a href="#">
  9. <?=$objResult1['Image_Date'];?></a>
  10. </li>
  11. <?
  12. }
  13. ?>

The following is i tried it out to fetch from database.But It only show (Year ,Month,day) format.

  1. <?
  2. $sql = "SELECT * FROM ShowFillter GROUP BY DATE_FORMAT(Image_Date, '%d/%m/%Y') order by DATE_FORMAT(Image_Date, '%d/%m/%Y') desc";
  3. $objQuery = mysql_query($sql) or die ("Error Query [".$sql."]");
  4. while($objResult1 = mysql_fetch_array($objQuery))
  5. {
  6. ?>
  7. <li class="filter" data-filter="<?=$objResult1['Image_Date'];?>">
  8. <a href="#">
  9. <?=$objResult1['Image_Date'];?></a>
  10. </li>
  11. <?
  12. }
  13. ?>

Here is the result result Is it possible to fetch (day,month,year) format? If its possible ,guide me please.

Thanks :)

</div>

展开全部

  • 写回答

3条回答 默认 最新

  • dtdfj08626 2016-09-11 22:44
    关注

    When you print your image date do:

    <?=date('d-m-Y', strtotime($objResult1['Image_Date])); ?>
    

    This will echo 27-12-2013

    More here http://php.net/manual/en/function.date.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部