--创建函数 周日是最后一天。。。。如有需要 自行修改 create function GetWeek (@time1 datetime ) returns int as begin declare @return int set @return = (select datepart(d,@time1)/7 + (case when datepart(d,@time1)%7>datepart(weekday,@time1) then 2 when (datepart(d,@time1)%7 = 0 and datepart(weekday,@time1) = 7) then 0 else 1 end)) return @return end