Emil K
Emil K

Reputation: 59

updating mysql table row by checking date using strtotime

I want to update row/rows if the current date is equals or greater to the date in the database. Example:

$sql = "UPDATE ca_dreams SET d_matured_status=1 WHERE d_pay_date='"
       . time() . "'";

How can I get d_pay_date to be converted to time using strtotime then compared to time().

Please note I want this to update as many rows as possible.

Upvotes: 2

Views: 214

Answers (1)

Qirel
Qirel

Reputation: 26480

time() is a PHP function, and you don't need to involve PHP when MySQL has functions which are just as usable.

What you'll need is DATE() to convert the d_pay_date column to a date (if it's already a specific date and not a timestamp, you don't need this function), then check against CURDATE(). Then compare against dates with <= (less or equal to).

$sql = "UPDATE ca_dreams SET d_matured_status=1 WHERE DATE(d_pay_date) <= CURDATE()":

Upvotes: 2

Related Questions