Check if a given date is past

后端 未结 3 1528
轮回少年
轮回少年 2021-01-17 14:57

I have a week calendar that holds events, and want that users can\'t add events for the past days. So I\'m tring to use a function like that:

if( strtotime($         


        
相关标签:
3条回答
  • 2021-01-17 15:20

    Simpler ->

    if(strtotime($this->day) < strtotime(date('Y-m-d')))
    {
       ...
    }
    else
    {
       ...
    }
    
    0 讨论(0)
  • 2021-01-17 15:27
    if(strtotime($this->day) < mktime(0, 0, 0)){
        // date is past
    } else {
        // date is not past
    }
    
    0 讨论(0)
  • 2021-01-17 15:35

    A timestamp never contains only the date, but is always down to the current second. strtotime($this->day) is going to return today's date at 0:00, while you are comparing it against now, say, 11:12.

    You could use strtotime("$this->day 12:59:59pm"); (if the format of $this->day allows for that) or use tomorrow's timestamp.

    0 讨论(0)
提交回复
热议问题