Beginner need help on Date Time function

Discussion in 'PHP' started by magnusexodus, Oct 26, 2011.

  1. #1
    I would like to know the best way to make comparison of expirydate in my database with current date . Currently the function is to find a record that will expired in 2 and 1 months then it will send reminder. The problem is it only compare only month but not with year. Please help new beginner here .

    // the sql command
    $sql="SELECT * FROM clients, clients_products WHERE clientsproducts_clientsid = clients_id AND (clientsproducts_reminder1 = 0 OR clientsproducts_reminder2 = 0) AND clientsproducts_expirydate >= '".date('Y-m-d')."'";

    //defination of current date
    $date = date('m-Y', strtotime($query_arr['clientsproducts_expirydate']));

    //defination of expiry date
    $exp_date = $query_arr["clientsproducts_expirydate"];
    $exp_date = date("d-m-Y", strtotime($exp_date) );

    //command on sending reminder
    if((abs(date('m-Y') - $date) == 2 || abs(date('m-Y') - $date) == 0) && ($reminder1 == 0)){
    echo "found a record before 2 months. (id:".$clientid.") ". (date('m-Y') - $date) . " <br>";
     
    Last edited: Oct 26, 2011
    magnusexodus, Oct 26, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Use MYSQL to find those fields

    WHERE YEAR(`field`) = YEAR(CUR_DATE()) AND
    DATE_ADD(`field`, 'INTERVAL 1 MONTH`)

    or something, please check the mysql manual for DATE_ADD :)
     
    EricBruggema, Oct 29, 2011 IP