mercredi 31 mai 2017

Issue with dates [ first of month ] php and Carbon

I have an issue comparing dates. When I want to know if a date (default php date) is between two Carbon dates. I get a difference in the first day of month.

$date = date("2017-05-01");
    $date2 = date("2017-05-31");
    $since = Carbon::now()->firstOfMonth();
    $to = Carbon::now()->lastOfMonth();//->subDay();//$now->lastOfMonth();
    $this->info('since '.$since);
    $this->info('to '.$to);
    $this->info('date '.$date);
    $this->info('date2 '.$date2);
    $this->info("-------------------");
    if($date>= $since && $date <= $to ){
        $this->info('date in');
    }else{
        $this->info('date out');
    }
    if($date2>= $since && $date2 <= $to ){
        $this->info('date2 in');
    }else{
        $this->info('date2 out');
    }

The output is:

since 2017-05-01 00:00:00
to 2017-05-31 00:00:00
date 2017-05-01
date2 2017-05-31
-------------------
date out
date2 in

I expect $date output be 'date in'. Whats wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rdaSiN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire