Tuesday, March 7, 2017

How do I retrieve Month and Year from SQL query>

I have the below snippet which returns month from my created_at timestamp. I am wanting this to return as MM-YYYY but not sure of the syntax. This is in a laravel implementation. I have tried to add 'MONTH, YEAR' but no luck.

$data = [
        'data' => Payment::selectSub('MONTH(created_at)', 'month')
        ->selectSub('SUM(payment_amount)', 'total_payments')
        ->groupBy('month')
        ->get()];   



via Eden WebStudio

Advertisement