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

Community
  • 1
  • 1
Juan Garcia
  • 843
  • 2
  • 11
  • 34

1 Answers1

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.

O. Jones
  • 103,626
  • 17
  • 118
  • 172