Reputation: 3472
Is it possible to use mysql date add or sub with a variable if I set it.
UPDATE table SET time = DATE_ADD(NOW(), INTERVAL $minutes MINUTES);
I have tried but can't get it working?
Thanks
Upvotes: 1
Views: 1973
Reputation: 73011
Coming in late to advocate protection from SQL Injection.
$qry = 'UPDATE table SET time = DATE_ADD(NOW(), INTERVAL ' . (int)$minutes . ' MINUTE)';
Note: Credit to diEcho and fivedigit for their foundational answers.
Upvotes: 3
Reputation: 18682
Assuming you're using PHP to get the expression part of DATE_ADD
done right, you're using MINUTES
rather than MINUTE
, which is the unit you're looking for:
UPDATE table SET time = DATE_ADD(NOW(), INTERVAL $minutes MINUTE);
Also see the MySQL documentation
Upvotes: 4
Reputation: 54052
TRY
$qry = "UPDATE table SET time = DATE_ADD(NOW(), INTERVAL ".$minutes." MINUTE) ";
Upvotes: 2