获取当前月一共几天
(1)
DECLARE @NOW DATETIME
DECLARE @LastDayOfThisMonth DATETIME
SET @NOW = GETDATE()
--SET @LastDayOfThisMonth = DATEADD(MONTH, 1, @NOW - DAY(@NOW) + 1) - 1
SET @LastDayOfThisMonth = DATEADD(MONTH,1, @NOW - DAY(@NOW)+1)-1
select @NOW
SELECT DAY(@LastDayOfThisMonth)
(2)
declare @date datetime
set @date = getdate()--'2008-12-9'
select cast(
-- 下个月的第一天
dateadd(month,datediff(month,0,@date)+1,0)
-
-- 这个月的第一天
dateadd(month,datediff(month,0,@date),0)
as int )
获取当前月的第一天和最后一天
DECLARE @NOW DATETIME
DECLARE @FistDayOfThisMonth DATETIME
DECLARE @LastDayOfThisMonth DATETIME
SET @NOW = GETDATE()
SET @FistDayOfThisMonth = @NOW - DAY(@NOW) + 1
SET @LastDayOfThisMonth = DATEADD(MONTH, 1, @NOW - DAY(@NOW) + 1) - 1
SELECT @FistDayOfThisMonth
SELECT @LastDayOfThisMonth