Goodspeed

导航

[SQL] 上月的月头和月尾

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

posted on 2004-09-20 10:50  Goodspeed  阅读(1584)  评论(0编辑  收藏  举报