在PHP& MySQL显示日期月份年份数据库中的格式

时间:2017-11-14 10:22:02

标签: php mysql date calendar

我在数据库中添加了一些日期&使用PHP&数据库从数据库中选择这些日期。 MySQL代码并以月份格式显示这些日期。我使用以下代码: -

enter image description here

我的结果如下: -

2017-01-16 January
2017-01-26 January
2017-01-27 January
2017-02-02 February
2017-03-21 March
2017-03-22 March

我想以这种格式显示月份日期: -

 January 
    2017-01-16
    2017-01-26
    2017-01-27
February
    2017-02-02 
March
    2017-03-21
    2017-03-22 

请帮忙。

1 个答案:

答案 0 :(得分:0)

    $mo1 = "";
    $qry = "SELECT DISTINCT ac_date FROM calender";
    $exe = mysql_query($qry);
    while($row = mysql_fetch_array($exe)) {
         $ac_date = $row['ac_date'];
         $dateElements = explode('/', $ac_date);
         switch ($dateElements[0]){  

            case '01'    :  $mo = "January"; break;
            case '02'    :  $mo = "February";break;
            case '03'    :  $mo = "March";  break;
            case '04'    :  $mo = "April"; break;
            case '05'    :  $mo = "May"; break;
            case '06'    :  $mo = "June"; break;
            case '07'    :  $mo = "July"; break;
            case '08'    :  $mo = "August"; break;
            case '09'    :  $mo = "September"; break;
            case '10'    :  $mo = "October";break;  
            case '11'    :  $mo = "November";break;
            case '12'    :  $mo = "December"; break;
    }
    if($mo1 != $mo){$activity.="<tr><td>$mo</td></tr>;}
    $activity.="<tr>
            <td>$ac_date </td>
                      </tr>";
    $mo1=$mo;   
  }