34,594
社区成员
发帖
与我相关
我的任务
分享
select datediff(day,'1988-4-6','2010-08-30')--8181 days
select datediff(month,'1988-4-6','2010-08-30')--268 months
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col1] datetime,[col2] datetime)
insert [tb]
select '2010-08-30','1988-4-6'
go
select
datediff(dd,col2,col1) as 相差天数,
datediff(mm,col2,col1) as 相差月数
from
tb
/**
相差天数 相差月数
----------- -----------
8181 268
(1 行受影响)
**/
select DATEDIFF(month ,'1988-4-6','2010-08-30'),
DATEDIFF(day ,'1988-4-6','2010-08-30')