How to compare two dates without years in php?

前端 未结 3 606
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 06:18

I would like to compare the two dates ,one date is which the 02 aug 1921 , and the second date is present date.How to compare the old date and present date day and month .if

3条回答
  •  伪装坚强ぢ
    2021-01-20 07:20

    If you are on PHP 5.3 you can use the new DateTime class:

    $oDate1 = new DateTime( $datetime1 );
    $oDate2 = new DateTime( $datetime2 );
    
    if( $oDate1->format('m-d') == $oDate2->format('m-d')
      echo 'yes';
    

提交回复
热议问题