dimanche 17 mars 2019

How do I query current and previous months data from a DB that uses UNIX EPOCH time?

I am trying to query a DB that is in UNIX EPOCH time format, so I can't use any of the standard modifiers that I am used to. I heard Carbon was useful for these things however I still haven't mastered it's use.

    $date = Carbon::today();

    /* Yearly Realtime Consumption data feed */
    $this_months_values = (new $propdash->custommenuitems->monthly_real_time_feed)::where('time',$date->copy()->format('m'))->sum('data');
    $one_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $two_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $three_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $four_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $five_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $six_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $seven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $eight_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $nine_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $ten_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');
    $eleven_month_agos_values = (new $propdash->custommenuitems->monthly_real_time_feed)::sum('data');

So how would I go about doing that?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire