现在的位置: 首页 > 综合 > 正文

[SQL] 上月的月头和月尾

2011年12月25日 ⁄ 综合 ⁄ 共 315字 ⁄ 字号 评论关闭
DECLARE @now datetime,@LastMonth datetime
DECLARE @star datetime,@end datetime

SET @now = DATEADD(dd,DATEDIFF(dd,'1900-1-1',getDATE()),'1900-1-1'--当前日期
SET @LastMonth = DATEADD(mm,-1,@now)  -- 上个月的今天
SET @star = @LastMonth - DAY(@now)+1 -- 上月头
SET @end = DATEADD(ss,-1,@star+32-DAY(@star+32-1)) --上个月尾
SELECT @star,@end

抱歉!评论已关闭.