Trying to extract rows from a database where the renewal_date
is sooner than 30 days with this code:
..but not getting the results I expected. Where am I going wrong?
is sooner than 30 days with this code:
Code:
//get todays date
$today = getdate();
//format date to the same format as "renewal_date" datestamp colummn in database ie YYYY-MM-DD - "mday" = day of month, "mon" = month, "year" = year
$todaystamp=$today["year"]."-".$today["mon"]."-".$today["mday"];
echo "Todays date: $todaystamp";
$SQL = " SELECT id, business_name, renewal_date FROM listings WHERE paid = '01' AND $todaystamp - 30 < renewal_date";
$retid = mysql_db_query($db, $SQL, $cid);
if (!$retid) { echo( mysql_error()); }
while ($row = mysql_fetch_array($retid)) {
$id = $row["id"];
$business_name = $row["business_name"];
$email = $row["email"];
$renewal_date = $row["renewal_date"];
echo "Soon due for renewal:";
echo "<br/>";
echo "$id";
}
..but not getting the results I expected. Where am I going wrong?