本文共 626 字,大约阅读时间需要 2 分钟。
周: Dateadd(wk,datediff(wk,0,getdate()),-1) Dateadd(wk,datediff(wk,0,getdate()),6) 月:Dateadd(mm,datediff(mm,0,getdate()),0) Dateadd(ms,-3,dateadd(mm,datediff(m,0,getdate())+1,0)) 年: Dateadd(yy,datediff(yy,0,getdate()),0) Dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate())+1, 0)) 注:上面的SQL代码只是一个时间段 例: 下面的SQL的条件部分,就是查询时间段在本周范围内的: Where Time BETWEEN Dateadd(wk,datediff(wk,0,getdate()),-1) AND Dateadd(wk,datediff(wk,0,getdate()),6) select @begintime = Dateadd(wk,datediff(wk,0,getdate()),-1) select @endtime = Dateadd(wk,datediff(wk,0,getdate()),6) |
转载地址:http://nlolo.baihongyu.com/