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

前端 未结 6 980
醉话见心
醉话见心 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:11

    Use DateTime() PHP objects.

    Considering you have an array with user info from mysql query result: ($userData['suscriptionDate'])

    $today = new DateTime();
    
    $userSuscription = new DateTime($userData['suscriptionDate']);
    
    if ( $today->format('d') == $userSuscription->format('d') && $today->format('m') == $userSuscription->format('m')) {
    
        echo 'Congratulations!!';
    }
    

提交回复
热议问题