如何使用年份的周数来获取周日期 [英] how to get week dates by using week number of the year

查看:98
本文介绍了如何使用年份的周数来获取周日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我们提供当周的周数如何获得该周的日期



谢谢和问候

Lakshman

Hi
we are providing present week number how to get dates in that week

Thanks & Regards
Lakshman

推荐答案

这很复杂,因为周数与固定的开始日期无关:1月特定年份的第一年可以在上一年的第50周,第51周或第52周,或当年的第1周 - 并且取决于何时控制当前一周的开始日期。

https://en.wikipedia.org/wiki/ISO_week_date [ ^ ]



我要做的是设置一个按年份编制索引并提供的表格每年第1周的开始日期,然后将周数乘以7以获得实际日期。

或者您可以按照链接中的算法进行操作!
That's complicated, because "week number" doesn't relate to a fixed start date: January the first of a particular year can be in week 50, 51, or 52 of the previous year, or week 1 of the current year - and depending on when that is controls what date the current week starts with.
https://en.wikipedia.org/wiki/ISO_week_date[^]

What I would do set up a table which indexes by year and provides the start date for week 1 of each year, and then add the week number times 7 to that to get the actual date.
Or you could follow the algorithm in the link!


DECLARE @WeekNo in t = 15

DECLARE @Year int = 2013



SELECT DATEADD(周刊,@ WeekNo-1,DATEADD(yy,@ Year-) 1900,0))AS WeekStart,

DATEADD(wk,@ WeekNo,DATEADD(yy,@ Year-1900,0)) - 1 AS WeekEnd
DECLARE @WeekNo int= 15
DECLARE @Year int=2013

SELECT DATEADD(wk,@WeekNo-1,DATEADD(yy,@Year-1900,0)) AS WeekStart,
DATEADD(wk,@WeekNo,DATEADD(yy,@Year-1900,0))-1 AS WeekEnd


这篇关于如何使用年份的周数来获取周日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆