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>";
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