Check if todays date is between two other dates

后端 未结 3 570
攒了一身酷
攒了一身酷 2021-01-24 06:27

I am trying to check if todays date is between START and STOP date of a period, Winter, summer, spring etc..

and if the todays date is between, lets say.. the winter per

3条回答
  •  伪装坚强ぢ
    2021-01-24 06:59

    If you use DateTime object—which is by far the best approach—you are able to compare these with the regular comparators, e.g.:

    $date1 = new DateTime('today');
    $date2 = new DateTime('2014-04-04');
    
    if ($date1 < $date2) echo 'Past';
    else if ($date1 == $date2) echo 'Present';
    else echo 'Future';
    

    See documentation: http://php.net/manual/en/datetime.diff.php#example-2368

提交回复
热议问题