2017-03-29 50 views

回答

0

代價:

  1. 您已創建行動歷史模型。
  2. 店日期爲30-03-2017(日 - 月 - 年)

注意
第()將只返回一個記錄。您可以使用 - > get()進行多條記錄,但是您需要循環結果。

方法1:

$result = actionhistory::select(DB::raw('MONTH(actiondate),YEAR(actiondate)'))->get(); 

方法2:

$result = DB::table('actionhistory')->select(DB::raw('MONTH(actiondate),YEAR(actiondate)'))->get(); 

方法3:

$actionhistory = new actionhistory(); 
$result = $actionhistory->select(DB::raw('MONTH(actiondate),YEAR(actiondate)'))->get(); 

在所有上述實現方法具DS(1,2,3)結果將包含以下

[MONTH(actiondate)] => 3 
[YEAR(actiondate)] => 2017 

方法4:用碳實例

$result = actionhistory::first(); 

OR

$result = DB::table('actionhistory')->first(); 

OR

$result = $actionhistory->first(); 

現在包括碳和使用格式

$month = Carbon::parse($sql->created_date)->format('m'); // month will be 3 
$year = Carbon::parse($sql->created_date)->format('y'); // year will be 2017 
相關問題