Currently I have an update that sets a column like this:
UPDATE ... SET date_time = DATE_SUB(NOW(), INTERVAL 8 DAY)
...
So, date_time
will hold the current date minus 8 days. I have a variable in my PHP code that holds seconds. And I want to be able to subtract that from NOW() too. So, if this variable holds 299928 seconds ($seconds = 299928), I would like to be able to do:
UPDATE ... SET date_time = DATE_SUB(NOW(), INTERVAL 8 DAY, $seconds)
. I fail to see how would I convert those seconds in a way that I can use in my MYSQL query, taking into account that I also want to subtract the 8 day interval.
Thanks
One option is to simply use another DATE_SUB function, wrapping your existing expression:
= DATE_SUB(DATE_SUB(NOW(), INTERVAL 8 DAY), INTERVAL 299928 SECOND)
Since your current expression is returning a DATETIME
, it's valid to use that function as the argument of another function that expects a DATETIME
. (Similar to the way the NOW() function is used as an argument in your existing DATE_SUB
function.)