如何从给定的年份和周数中获取上一周的周数(和年份数)?
e.g。
declare @year int = 2014;
declare @week int = 53;
我想获得2014年和52年。
答案 0 :(得分:0)
与@AFract一样,根据您使用的RDBMS,您可以这样做。
DECLARE @year int;
DECLARE @week int;
DECLARE @date datetime;
SET @year = 2014;
SET @week = 53;
SET @date = '01/01/' + CAST ( @year AS varchar ) ;
SET @date = DATEADD ( week , @week - 2 , @date ) ;
SELECT DATEPART ( year , @date ) AS 'Year' ,
DATEPART ( week , @date ) AS 'Week';