2个回答
展开全部
CREATE function Week2Day(@intYear integer,@intWeek integer) returns varchar(50) as begin declare @dateFirstDayOfYear datetime declare @dateFirstDayOfWeek datetime declare @dateLastDayOfWeek datetime set @dateFirstDayOfYear=convert(smalldatetime,convert(varchar(4),@intYear) + '-1-1') set @dateFirstDayOfWeek=dateadd(day,1-datePart(weekday,@dateFirstDayOfYear),dateAdd(week,@intWeek-1,@dateFirstDayOfYear)) set @dateLastDayOfWeek=dateadd(day,6,@dateFirstDayOfWeek) RETURN convert(varchar(10),@dateFirstDayOfWeek,11) + '~' + convert(varchar(10),@dateLastDayOfWeek,11) end
展开全部
自己把它写成存储过程,传个日期:
DECLARE @NOWDATE VARCHAR(10)
SET @NOWDATE='2015-03-06'
--记录日期第几周
DECLARE @NOW_WW INT
SELECT @NOW_WW=DATEPART(WW,@NOWDATE)
--记录日期星期几
DECLARE @NOW_DW INT
SELECT @NOW_DW=DATEPART(DW,@NOWDATE)
IF(@NOW_DW > 5)
BEGIN
SET @NOW_WW = @NOW_WW + 1
END
ELSE
BEGIN
IF(DAY(@NOWDATE)>=26)
BEGIN
SET @NOW_WW = @NOW_WW + 1
END
END
SELECT @NOW_WW
DECLARE @NOWDATE VARCHAR(10)
SET @NOWDATE='2015-03-06'
--记录日期第几周
DECLARE @NOW_WW INT
SELECT @NOW_WW=DATEPART(WW,@NOWDATE)
--记录日期星期几
DECLARE @NOW_DW INT
SELECT @NOW_DW=DATEPART(DW,@NOWDATE)
IF(@NOW_DW > 5)
BEGIN
SET @NOW_WW = @NOW_WW + 1
END
ELSE
BEGIN
IF(DAY(@NOWDATE)>=26)
BEGIN
SET @NOW_WW = @NOW_WW + 1
END
END
SELECT @NOW_WW
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询