获得当月的天数?

 

--方法一
DECLARE @month int, @year int
SELECT @month = 6, @year = 2004
SELECT DATEPART(dd,DATEADD(m,1,CAST(STR(@month) + '/01/' + STR(@year) as
datetime)) - 1)
--方法二
DECLARE @DATE DATETIME
SET @DATE = GETDATE()

SELECT CAST(
 -- First day of next month
 DATEADD(MONTH,DATEDIFF(MONTH,0,@DATE)+1,0)
 -
 -- First day of current month
 DATEADD(MONTH,DATEDIFF(MONTH,0,@DATE),0)
 AS INT )

--方法三
declare @dateX smalldatetime
set @dateX = '2001-1-3'
--本月多少天
SELECT 32-Day(@datex+32-Day(@datex))
posted @ 2007-05-11 09:46  '.Elvis.'  阅读(125)  评论(0编辑  收藏  举报