Zhao Tian 博客

计算日期同期环比

2018-1-11 15:28:46


declare @Start datetime= CONVERT(datetime,'2017-7-5',101)
declare @End datetime=CONVERT(datetime,'2017-7-6',101)
declare @day int=DATEDIFF ( day ,@End ,@Start)    
declare @LastStart datetime=  DATEADD(day,@day-1 ,@Start)
declare @LastEnd datetime=DATEADD(day,@day-1 ,@end)

select @Start, @End,@Start,DATEADD(ss,-1,DATEADD(DAY,1,@End) )  
select @LastStart, @LastEnd,@LastStart, DATEADD(ss,-1,DATEADD(DAY,1,@LastEnd) )
select *  from   t1 where  t1 BETWEEN @Start   and DATEADD(ss,-1,DATEADD(DAY,1,@End) )  
select *  from   t1 where  t1  BETWEEN @LastStart   and  DATEADD(ss,-1,DATEADD(DAY,1,@LastEnd) )

修改时间 | 阅读(26) |评论(0) |返回首页

评论