Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

MYSQL TIMESTAMPDIFF To Compare Dates

Below is a mysql query which joins 3 tables and outputs data that had been inserted into the database within 2 hours(120 minutes) time difference. In the following case, the 2 hour time difference had been checked between 2 tables. The mysql function TIMESTAMPDIFF() was used to compare the dates. The function compares 2 columns and can be used to compare minutes, dates and years. In our case, we used minutes. TIMESTAMPDIFF(minute, columna, columnb)

“select tbnm1.question, tbnm1.answer, tbnm1.firstname, tbnm1.email, tbnm1.lastname, tbnm1.representative, tbnm1.time, tbnm2.score, tbnm2.firstnm, tbnm3.helpText, tbnm2.DateReceived, TIMESTAMPDIFF(MINUTE,tbnm1.time,tbnm2.DateReceived) AS minutes, from prefix_tbnm3quiz_written as tbnm1, prefix_tbnm3quiz_1 as tbnm2, prefix_tbnm3quiz as tbnm3 WHERE tbnm3.question=tbnm1.question AND (TIMESTAMPDIFF(MINUTE,tbnm1.time,tbnm2.DateReceived)>-120 OR TIMESTAMPDIFF(MINUTE,tbnm1.time,tbnm2.DateReceived)<120) AND (tbnm1.email=tbnm2.emailaddress OR (tbnm1.firstname=tbnm2.firstnm AND tbnm1.lastname=tbnm2.lastname)) ORDER BY time DESC”;