0

I want calculate a "dynamic" timestampdiff where params are in tables and I have to make a query for extract it. Both params are stored like datetime. I try commands like this:

 timestampdiff(second,now(),'select date1 from dates where id=1;');

and the result is ERROR 1064, SQL Syntax error.

I have search in Google and SO and I have find some interesting comments in this question Calculate difference between two datetimes in MySQL

1 Answer 1

0

You are very close here. What you need is

SELECT timestampdiff(second,now(),date1)
  FROM dates
 WHERE id=1

Your attempt put a text string with your SQL statement in the third actual parameter to timestampdiff(). MySQL attempted to parse that as a datetime constant and gacked.

1
  • Certain, I see the error few seconds after post the question. Your answer work fine. Thanks @OllieJones Sep 8, 2014 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.