#Method One
select to_days(now()) - to_days('20120512')
#Method Two
select datediff(now(),'20120512')
#Method Three
select (datediff(curdate(), date(colunm_name1))- (select colunm_name2 from table_name2)) as o
from table_name1
本文介绍了使用SQL语言计算两个日期之间天数差的三种不同方法:第一种使用to_days函数,第二种采用datediff函数,第三种则通过当前日期与指定列的日期差减去从另一个表中获取的值来实现。
#Method One
select to_days(now()) - to_days('20120512')
#Method Two
select datediff(now(),'20120512')
#Method Three
select (datediff(curdate(), date(colunm_name1))- (select colunm_name2 from table_name2)) as o
from table_name1

被折叠的 条评论
为什么被折叠?