如何获得“周开始日期”和“周结束日期”从SQL Server中的周数? [英] How do you get the "week start date" and "week end date" from week number in SQL Server?
本文介绍了如何获得“周开始日期”和“周结束日期”从SQL Server中的周数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询计算会员在数据库中的婚礼日期...
I have a query that counts member's wedding dates in the database...
Select
Sum(NumberOfBrides) As [Wedding Count],
DATEPART( wk, WeddingDate) as [Week Number],
DATEPART( year, WeddingDate) as [Year]
FROM MemberWeddingDates
Group By DATEPART( year, WeddingDate), DATEPART( wk, WeddingDate)
Order By Sum(NumberOfBrides) Desc
如果结果集中每个星期的开始和结束,我该如何解决?
How do I work out when the start and end of each week represented in the result set?
Select
Sum(NumberOfBrides) As [Wedding Count],
DATEPART( wk, WeddingDate) as [Week Number],
DATEPART( year, WeddingDate) as [Year],
??? as WeekStart,
??? as WeekEnd
FROM MemberWeddingDates
Group By DATEPART( year, WeddingDate), DATEPART( wk, WeddingDate)
Order By Sum(NumberOfBrides) Desc
推荐答案
您可以找到星期几,并在日期添加日期,以获得开始和结束日期..
You can find the day of week and do a date add on days to get the start and end dates..
DATEADD(dd, -(DATEPART(dw, WeddingDate)-1), WeddingDate) [WeekStart]
DATEADD(dd, 7-(DATEPART(dw, WeddingDate)), WeddingDate) [WeekEnd]
你可能还想看看从日期开始剥离的时间。
You probably also want to look at stripping off the time from the date as well though.
这篇关于如何获得“周开始日期”和“周结束日期”从SQL Server中的周数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文