PAUL MENARD wrote:
Hello All,
I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables that have a DATETIME column. In my SELECT I am doing a JOIN to bring in both sets of rows. What I want is to subtract the DATETIME values to determine the number of seconds between their time. In the WHERE clause I also want to filter the selected rows if the difference in the DATETIME values is less that 900 (seconds).
Any help?
FPM

I don't really know if timestamps can be added or substracted. But I still found a way to help you.


SELECT UNIX_TIMESTAMP(first_stamp)-UNIX_TIMESTAMP(second_stamp) AS difference FROM table_name WHERE your_join_here HAVING difference>=900;

I also want to filter the selected rows if the difference in the DATETIME values is less that 900 (seconds)

I'm assuming, you were trying to mean that you DON'T values less than 900 seconds. If you meant the opposite, please switch the greater than sign.


--
No, but he says that all Gods are good :w
_________________________________________
Meet the guy at http://www.meetRajesh.com/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to