PHP check if two Datetimes are not on the same calendar day

后端 未结 3 887
庸人自扰
庸人自扰 2021-01-22 04:24

I have two Datetimes like this (the dates being actually $vars)

$startTime = \\DateTime::createFromFormat(\'Y/m/d H:i\', \'2015/01/01 23:00\');
$endTime = \\Date         


        
3条回答
  •  我在风中等你
    2021-01-22 05:24

    Comparing formatted dates is the right thing to do:

    $a->format('Y-m-d') === $b->format('Y-m-d')
    

    There is a method for that if you use Carbon:

    $dt1->isSameDay($dt2)
    

    So I recommend to use it instead of previous answers given here.

    http://carbondoc/docs/#api-comparison

提交回复
热议问题