Compare given date with today

前端 未结 13 2141
别那么骄傲
别那么骄傲 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:51

    Here you go:

    function isToday($time) // midnight second
    {
        return (strtotime($time) === strtotime('today'));
    }
    
    isToday('2010-01-22 00:00:00.0'); // true
    

    Also, some more helper functions:

    function isPast($time)
    {
        return (strtotime($time) < time());
    }
    
    function isFuture($time)
    {
        return (strtotime($time) > time());
    }
    

提交回复
热议问题