Compare given date with today

前端 未结 13 2144
别那么骄傲
别那么骄傲 2020-11-22 16:22

I have following

$var = \"2010-01-21 00:00:00.0\"

I\'d like to compare this date against today\'s date (i.e. I\'d like to know if this

13条回答
  •  不知归路
    2020-11-22 16:53

    If you do things with time and dates Carbon is you best friend;

    Install the package then:

    $theDay = Carbon::make("2010-01-21 00:00:00.0");
    
    $theDay->isToday();
    $theDay->isPast();
    $theDay->isFuture();
    if($theDay->lt(Carbon::today()) || $theDay->gt(Carbon::today()))
    

    lt = less than, gt = greater than

    As in the question:

    $theDay->gt(Carbon::today()) ? true : false;
    

    and much more;

提交回复
热议问题