sql server中常用到的日期汇总:
日期格式: YYYYMMDD
--获得今天
select statdate from ( select convert(varchar(8),getdate(),112) statdate ) a
--获得昨天
select statdate from ( select convert(varchar(8),getdate()-1,112) statdate ) a
--获取本月月初
select statdate from ( select convert(varchar(6),getdate(),112)+ '01' statdate ) a
select convert(varchar(8),getdate()-datepart(day,getdate())+1,112)
--获取上个月月末
select convert(varchar(8),getdate()-datepart(day,getdate()) ,112)
--获得年初
select statdate from ( select convert(varchar(4),year(getdate()),112)+ '0101' statdate ) a
select convert(varchar(8),getdate()-datepart(dayofyear,getdate())+1,112)