SQL SERVER獲得一個月全部的日期

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')
--從2016-04-01到如今全部天數get

SELECT DATEADD(DAY, number, CONVERT(DATETIME, '2016-04-01')) DataTime
FROM master..spt_values
WHERE type = 'P' AND number BETWEEN 0 AND DATEDIFF(DAY, '2016-04-01', GETDATE())ast

--從2016-04-01到如今全部月份date

SELECT DATEADD(MONTH, number, CONVERT(DATETIME, '2016-04-01')) month
FROM master..spt_values
WHERE type = 'P' AND number BETWEEN 0 AND DATEDIFF(MONTH, '2016-04-01', GETDATE())select

相關文章
相關標籤/搜索