SQLSERVER——获取本月余下的日期

select dt,(Datepart(weekday,dt)-1) week
from (
select convert(varchar(10),dateadd(dd,number,convert(varchar(8),getdate(),120)+'01'),120) as dt
from master..spt_values 
where type='P' 
and dateadd(dd,number,convert(varchar(8),getdate(),120)+'01')<=dateadd(dd,-1,convert(varchar(8),dateadd(mm,1,getdate()),120)+'01') 
and number+1>=DatePart(dd,GETDATE())
)t
order by dt

参考文献:https://www.cnblogs.com/shenyixin/p/5511084.html

原文地址:https://www.cnblogs.com/xiaoli9627/p/15069703.html