select dateadd(year, datediff(year, 0, getdate()), 0) --取当下年第一天日期
SELECT dateadd(year, datediff(year, 0, dateadd(year, 1, getdate())), -1) --取当下年最后一天日期
select convert(varchar(10),GETDATE(),120) -----将日期类型转换为文本
select datename(weekday,GETDATE()) --取今天所在的周数
select name from sysobjects where xtype='TR' --触发器查询
select convert(varchar(10),DATEADD(mm,DATEDIFF(mm,0,dateadd(month,-1,getdate())),0)),convert(varchar(10),dateadd(ms,-3,DATEADD(mm,DATEDIFF(mm,0,getdate()),0))) --取每月最开始日期和每月最后一天日期
A :
select CONVERT(varchar(10), DATEADD(day, 2 - DATEPART(weekday, dateadd(d,-2,getdate())),dateadd(d,-2,getdate())), 20),
DATEADD(d,7,CONVERT(varchar(10), DATEADD(day, 2 - DATEPART(weekday, dateadd(d,-2,getdate())),dateadd(d,-2,getdate())), 20))
---上周一到本周一
B :
select CONVERT(varchar(10),dateadd(week,-1,DATEADD(day, 2 - DATEPART(weekday, dateadd(d,-2,getdate())),dateadd(d,-2,getdate()))), 20),dateadd(week,-1,DATEADD(d,7,CONVERT(varchar(10), DATEADD(day, 2 - DATEPART(weekday, dateadd(d,-2,getdate())),dateadd(d,-2,getdate())), 20)))
--介于上上周一至上周日