如果我在mysql表中有一个datetime列,我怎样才能在几秒钟内得到NOW()与该列之间的区别?
答案 0 :(得分:5)
TIMEDIFF
你可以通过秒获得差异
SELECT TIME_TO_SEC(TIMEDIFF('2007-01-09 10:24:46','2007-01-09 10:23:46'));
或者
SELECT DATEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01') * 24*60*60;
// result: 86400 the difference in seconds for days.
或:
SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00');
// result: 79259 the difference in seconds with the time.
答案 1 :(得分:0)
试试这个:现在选择() - my_col AS my_diff