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' goselect datediff(dd,col2,col1) as 相差天数, datediff(mm,col2,col1) as 相差月数 from tb /** 相差天数 相差月数 ----------- ----------- 8181 268(1 行受影响) **/
datediff(month,startdate,enddate)
go
create table [tb]([col1] datetime,[col2] datetime)
insert [tb]
select '2010-08-30','1988-4-6'
goselect
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')