-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
CREATE TABLE timefun (
   id INTEGER NOT NULL PRIMARY KEY,
   t TIME
);

INSERT INTO timefun VALUES(1, '19:35');
INSERT INTO timefun VALUES(2, '20:00');
INSERT INTO timefun VALUES(3, '21:25');
INSERT INTO timefun VALUES(4, '21:45');
INSERT INTO timefun VALUES(5, '23:30');

SELECT *
FROM timefun;

SELECT *
FROM timefun
WHERE ABS(UNIX_TIMESTAMP(CONCAT('2000-1-1 ',t))-UNIX_TIMESTAMP(CONCAT('2000-1-1 ','19:50')))
= (SELECT MIN(ABS(UNIX_TIMESTAMP(CONCAT('2000-1-1 ',t))-UNIX_TIMESTAMP(CONCAT('2000-1-1 ','19:50')))) FROM timefun);

DROP TABLE timefun;
