CREATE TABLE t (d1 timestamp, d2 timestamp);
INSERT INTO t VALUES ('2010-03-11 12:00:00', '2010-03-30 05:00:00');
INSERT INTO t VALUES ('2010-03-11 12:00:00', '2010-03-30 13:00:00');
INSERT INTO t VALUES ('2010-03-11 00:00:00', '2010-03-30 13:00:00');
INSERT INTO t VALUES ('2010-03-10 12:00:00', '2010-03-30 13:00:00');
INSERT INTO t VALUES ('2010-03-10 12:00:00', '2010-04-01 13:00:00');
SELECT d2, d1, DATEDIFF(d2, d1) AS diff FROM t;
+---------------------+---------------------+------+
| d2 | d1 | diff |
+---------------------+---------------------+------+
| 2010-03-30 05:00:00 | 2010-03-11 12:00:00 | 19 |
| 2010-03-30 13:00:00 | 2010-03-11 12:00:00 | 19 |
| 2010-03-30 13:00:00 | 2010-03-11 00:00:00 | 19 |
| 2010-03-30 13:00:00 | 2010-03-10 12:00:00 | 20 |
| 2010-04-01 13:00:00 | 2010-03-10 12:00:00 | 22 |
+---------------------+---------------------+------+
5 rows in set (0.00 sec)
Daniel Vassallo
2010-03-30 14:49:36