I am trying to write a cron to update custom table.
The table has coupon code, status, start, end fields.
The status can be unused, used and expired.
Now there is a time limit to use the coupon. If the coupon is not used within 7 days, I want to set the status to expired.
I am trying to update the rows where status is unused and end is less than today date, and set status as expired.
When I run the script, the status for all rows is set as expired, regardless of date and status.
Here is the code
<?php
$format="Y-m-d";
$date=date($format);
$old_status = "unused";
//echo("$old_status");
$new_status = "expired";
//echo("$new_status");
$table = $modx->getFullTableName( 'coupon' );
$fields = array('status' => $new_status );
$result = $modx->db->update( $fields, $table, 'status = "' . $old_status . '"' AND 'end < "' . $date . '"' );
if(!$result)
{
echo mysql_error ();
}
else{
echo 'ok done';
}
?>
Where is the problem?