2016-07-12 25 views
0

このコードは、日付を次のように表示します。13-07-2016 月と年のみを表示したい。例:「2016年7月」 このコードを変更して月と年のみを取得して表示するにはどうすればよいですか? コード:Mysqlデータベースから月のみ表示

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

'' wll''と 'getDateFomate'は何をするのか分かりません。 –

+2

PHPにいくつかの[日付機能](http://php.net/manual/en/ref.datetime.php)がある場合... – tadman

+1

MYSQLには[日付機能](http://dev.mysql .com/doc/refman/5.7/ja/date-and-time-functions.html#function_date-format) – RiggsFolly

答えて

1
$date = $row['bill_date']; 
$month = date('F', strtotime($date)); 
$year = date('Y', strtotime($date)); 

<td><?php echo $month . ' ' . $year; ?></td> 
その場合
+0

Thanks a Ton! :) –

+0

あなたは大丈夫です= D –

0

ディスプレイテキストにスイッチを使用してみてください。このような何か:

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

など、他の文字とthath月を表示:strtotime():

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

それともような何かを行うことができ

show: display_text[0] + display_text[1] + "-" + month + ... 
+0

コードをよく知らないのですが、コードを変更できますか? –

+0

ソーリーファンドンド、私はPHPに熱心ではない。 [String handling](http://php.net/manual/es/ref.strings.php)と[switch structures](http://php.net/manual/es/control-structures.switch.php)を検索してみてください。 ) –

0

使用...

$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 
0

使用したい、そのデータを提供するために、クエリを修正ではなく、それは

SELECT DATE_FORMAT(theDateCol, '%M %Y') as theMonthAndYear, ... 
0
date_format($row['bill_date], "F Y"); 

Fクエリ投稿を操作しようとしている - >完全な月文字やY - > 4桁の年

+0

ちょっと説明しますか?そうでなければ、それはコメントのように見え、おそらくダウンボックスを得るでしょう – RiggsFolly

関連する問題