Compare given date with today

前端 未结 13 2157
别那么骄傲
别那么骄傲 2020-11-22 16:22

I have following

$var = \"2010-01-21 00:00:00.0\"

I\'d like to compare this date against today\'s date (i.e. I\'d like to know if this

13条回答
  •  暖寄归人
    2020-11-22 16:48

    Some given answers don't have in consideration the current day!

    Here it is my proposal.

    $var = "2010-01-21 00:00:00.0"
    $given_date = new \DateTime($var);
    
    if ($given_date == new \DateTime('today')) {
      //today
    }
    
    if ($given_date < new \DateTime('today')) {
      //past
    }
    
    if ($given_date > new \DateTime('today')) {
      //future
    }
    

提交回复
热议问题