mercredi 27 juillet 2016

Laravel date changing when I update a variable

I'm writing a scope query and I'm passing in a fetch_date to pull things from the DB table based on the created_at timestamp.

I'm trying to find all records for a month, but the variable $fetch_date keeps changing whenever I try the following:

    //$fetch_date is a carbon instance and is equal to the month the user selected 
    //ie: Carbon {#221 ▼
    //    +"date": "2016-07-01 00:00:00.000000"

    //Create the next_month
    $next_month = $fetch_date->addMonth();
    //Format next_month as a string
    $next_month = $next_month->format('Y-m-d');
    //Format fetch_date as a string
    $fetch_date = $fetch_date->format('Y-m-d');

    dd($fetch_date);
    //This now gives me 2016-08-01 - why?

Why does the fetch_date change? I'm essentially trying to keep the $fetch_date as the current month and the $next_month to simply be the start of the next month.

I'm guessing there's a real simple reason to this I'm just overlooking.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire