Compare only day and month without year in php ex. birth date

前端 未结 6 930
醉话见心
醉话见心 2021-01-22 21:45

I want to compare current date\'s day and month with subscription date\'s day and month only. ex.current date(d-m) = 3-6 and I want compare it with any other

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 22:25

    The trick in this is to let the month come first. This way PHP can compare the numbers by highest value. Take a look at the following example:

    $aDate = DateTime::createFromFormat('m-d', '05-20');
    $bDate = DateTime::createFromFormat('m-d', '06-29');
    
    if ($aDate->format('md') > $bDate->format('md')) {
        echo "'aDate' is bigger than 'bDate'";
    }
    

提交回复
热议问题