php compare current date with dates stored in database

后端 未结 5 1330
傲寒
傲寒 2021-01-16 08:32

I am trying coding a php script where i want to extract a date field from a database table,store this date compare it with todays. To see if the data. from database has pass

相关标签:
5条回答
  • 2021-01-16 08:32

    Use strtotime()

    while($info = mysqli_fetch_assoc($result)){
        if(strtotime(date("Y-m-d")) > strtotime($result)){
            exit;
            echo "Success";
        }
        elseif(strtotime(date("Y-m-d")) < strtotime($result)){
            return true;
            echo "Failure";
        }
    }
    
    0 讨论(0)
  • 2021-01-16 08:35

    You can use below query :

    $sql="SELECT (CASE WHEN DATE(NOW()) > enddate THEN 'success' ELSE 'failed' END) AS mystatus FROM campaigns WHERE id=".$data['camp'];
    

    Then you just need to call mystatus column from the query.

    0 讨论(0)
  • 2021-01-16 08:36

    You have to do:

    if(date("Y-m-d") > $info['enddate']) {
    
    0 讨论(0)
  • 2021-01-16 08:37

    I spend lot of time to compare only dates and i found a solution like this

    Always set format like date('Y-m-d')

    $dateTo='2016-08-07';
    if(date("Y-m-d", strtotime($dateTo)) > date('Y-m-d')){
       echo 'yes';
    }else{
       echo 'no';
    }
    
    0 讨论(0)
  • 2021-01-16 08:51

    Youl could just let MySQL worry about it.

    SELECT DATEDIFF(NOW(),enddate) FROM campaigns WHERE id=".$data['camp']
    

    That will return the number of days between the two dates. See the manual for DATEDIFF.

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