dongyinzheng6572
2016-07-12 19:14
浏览 168
已采纳

从Mysql数据库中仅显示月份

This code displays date as: 13-07-2016 I want to display only month and year. Example: "July 2016" How do I modify this code so that it gets Only month and year and displays it. Code:

   <td><?=$this->wll->getDateFormate(6,$row['bill_date'])?></td>

图片转代码服务由CSDN问答提供 功能建议

此代码显示日期:13-07-2016 我想只显示月份和年份。 示例:“2016年7月” 如何修改此代码以使其仅显示月份和年份并显示它。 编码:

 &lt; td&gt;&lt;?=  $ this-&gt; wll-&gt; getDateFormate(6,$ row ['bill_date'])?&gt;&lt; / td&gt; 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • duanou8504 2016-07-12 19:22
    已采纳
    $date = $row['bill_date'];
    $month = date('F', strtotime($date));
    $year = date('Y', strtotime($date));
    
    <td><?php echo $month . ' ' . $year; ?></td>
    
    已采纳该答案
    打赏 评论
  • dongyi5817 2016-07-12 19:21

    Try using a switch on your display text. Something like this:

    var month_number = display_text[3] + display_text[3];
    var month;
    switch (month_number)
        case "01":
            month = "Jan";
            break;
    ...
    

    And display thath month with the other characters, like:

    show: display_text[0] + display_text[1] + "-" + month + ...
    
    打赏 评论
  • douyimin1083 2016-07-12 19:21

    Use strtotime():

    $time=strtotime($dateValue);
    $month=date("F",$time);
    $year=date("Y",$time);
    

    Or you can do something like...

    $dateElements = explode('-', $dateValue);
    $year = $dateElements[0];
    
    echo $year;    //2012
    
    switch ($dateElements[1]) {
    
       case '01'    :  $mo = "January";
                       break;
    
       case '02'    :  $mo = "February";
                       break;
    
       case '03'    :  $mo = "March";
                       break;
    
         .
         .
         .
    
       case '12'    :  $mo = "December";
                       break;
    
    
    }
    
    echo $mo;      //January
    
    打赏 评论
  • doushui3061 2016-07-12 19:25

    In that case amend your query to provide that data you want to use rather than trying to manipulate it post query

    SELECT DATE_FORMAT(theDateCol, '%M %Y') as theMonthAndYear, ...
    
    打赏 评论
  • dq804806 2016-07-12 19:28
    date_format($row['bill_date], "F Y");
    

    F -> Full Month Letters and Y -> 4 digit Year

    打赏 评论

相关推荐 更多相似问题