PHP: Date larger than current date

后端 未结 7 860
梦毁少年i
梦毁少年i 2020-12-01 18:02

I have this code:

$curdate = \'22-02-2011\';

$mydate = \'10-10-2011\';                     

if($curdate > $mydate)
{
    echo \'

        
相关标签:
7条回答
  • 2020-12-01 18:31

    it's VERY simple

    $curdate = '2011-02-22';
    $mydate = '2011-10-10';                     
    
    if($curdate > $mydate)
    {
        echo '<span class="status expired">Expired</span>';
    }
    
    0 讨论(0)
  • 2020-12-01 18:33
    if(strtotime($curdate) > strtotime($mydate))
    {
    ...
    }
    
    0 讨论(0)
  • 2020-12-01 18:36
    $currentDate = date('Y-m-d');
    
    $currentDate = date('Y-m-d', strtotime($currentDate));
    
    $startDate = date('Y-m-d', strtotime("01/09/2019"));
    
    $endDate = date('Y-m-d', strtotime("01/10/2022"));
    
    if (($currentDate >= $startDate) && ($currentDate <= $endDate)) {
    
        echo "Current date is between two dates";
    
    } else {
    
        echo "Current date is not between two dates";  
    }
    
    0 讨论(0)
  • 2020-12-01 18:41

    The problem is that your current variables are strings, and not time variables.

    Try this out:

    $curdate = strtotime('22-02-2011');
    
    $mydate = strtotime('10-10-2011');  
    
    0 讨论(0)
  • 2020-12-01 18:42
    $row_date = strtotime($the_date);
    $today = strtotime(date('Y-m-d'));
    
    if($row_date >= $today){
         -----
    }
    
    0 讨论(0)
  • Use the PHP date/time classes to convert these string representations into something you can directly compare using getTimestamp() to compare the UNIX times.

    If you're sure all your dates are in this format, you can string slice them into YYYY-MM-DD, and a string comparison will function correctly then.

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