您的位置: bluesailor散记——
« SQL笔记:convert及replace函数SQL笔记:查询当日数据 »

SQL笔记:dateadd函数

分类: 读书笔记 发布: bluesailor 浏览: 日期: 2008年8月2日

declare @dt datetime
select @dt='2008-01-13'
select dateadd(year,20,@dt)

结果: 2028-01-13 00:00:00.000

 指定日期过生日的做法:


declare @t table(ID int,Name varchar(10),Birthday datetime)
insert @t select 1,'a','1901-01-22'
union all select 2,'b','1980-12-02'
union all select 3,'c','1982-6-02'
union all select 4,'d','1980-12-02'
union all select 5,'e','1932-06-16'

declare @dt1 datetime,@dt2 datetime
select @dt1='2003-05-01',@dt2='2003-07-02'
select * from @t
where dateadd(year,datediff(year,Birthday,@dt1),Birthday)
 between @dt1 and @dt2

 

 

 

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-Blog 1.8 Spirit Build 80722

Copyright Lunji.com Some Rights Reserved.