I am using MySql (and PHP) to try to find out if there are any records in my table that are less than 10 minutes old. Basically this is part of a time-keeping script, and I create a new entry if it has been more than 10 minutes (no results) or I update the current entry if it is less than 10 minutes.
Basic table structure (unimportant fields removed):
CREATE TABLE `timesheet` (
`RecordId` int(8) NOT NULL auto_increment,
`Timestamp` datetime NOT NULL,
PRIMARY KEY (`RecordId`)
) AUTO_INCREMENT=56 ;
INSERT INTO `timesheet` VALUES (55, '2010-03-30 18:19:00');
So, I am using this query:
SELECT * FROM timesheet WHERE Timestamp<='DATE_SUB(NOW(), INTERVAL 10 MINUTE)' ORDER BY Timestamp DESC LIMIT 1;
The problem is that it always returns my latest record...even if it is older than 10 minutes.
What am i doing wrong? Thanks!