SELECT DATEADD(DAY,-1,'20121212')
SELECT DATEADD(DAY,-1,GETDATE())
SELECT DATEADD(MONTH,-1,'20121212')
SELECT DATEADD(MONTH,-1,GETDATE())
SELECT DATEADD(YEAR,-1,'20121212')
SELECT DATEADD(YEAR,-1,GETDATE())
SQL 取前一天、一月、一年的时间
SQL 如下:
取出本周的最后一天
select DATEADD(WK,DATEDIFF(WK,0,GETDATE()),6)
本周 周日开始至周六为一周
select * from tb where datediff(week , 时间字段 ,getdate()) = 0
上周
select * from tb where datediff(week , 时间字段 ,getdate()) = 1
下周
select * from tb where datediff(week , 时间字段 ,getdate()) = -1
----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
--上月
Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 1
--本月
Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0
--下月
Select * From TableName Where DateDiff(mm, GetDate(), DateTimCol ) = 1
昨天:dateadd(day,-1,getdate())
明天:dateadd(day,1,getdate())
上月:month(dateadd(month, -1, getdate()))
本月:month(getdate())
下月:month(dateadd(month, 1, getdate()))
---------------------------------------------------------------------------------
--昨天
Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 1
--明天
Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) = 1
--最近七天
Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) <= 7
--随后七天
---------------------------------------------------------------------------
当前年
select 提出日期, datepart(year,getdate()) as 当前年 from 供方资料表
前一年
select 提出日期, datepart(year,getdate())-1 as 当前年 from 供方资料表
后一年
select 提出日期, datepart(year,getdate())+1 as 当前年 from 供方资料表
转载:https://blog.csdn.net/mfkpie/article/details/46772945