如何在sql中查找当前周数据? [英] How to find current weeks data in sql ?
本文介绍了如何在sql中查找当前周数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想返回当前的周数据,即使我是在当天中午。我想回复本周的记录。
请建议
以下是我到目前为止所尝试的。
Hi ,
I want to return current weeks data , even if i am in the middle of the day . i want to return record of this week.
Please suggest
below is what i tried so far .
SELECT *
FROM objectives
WHERE CompetionDate > = DATEADD(wk,DATEDIFF(wk,0, GETDATE() -1 ),0)
and Year(CompetionDate) = 2015
and Comp_Id=161
推荐答案
sqlservercentral.com [ ^ ]有一些有用的日期片段。
尝试类似(警告 - 未经测试)
sqlservercentral.com[^] has some useful snippets for dates.
Try something like (caveat - untested)
SELECT *
FROM objectives
WHERE CompetionDate >= dateadd(wk, datediff(wk, 0, getdate()), 0)
AND CompetionDate < dateadd(wk, datediff(wk, 0, getdate()) + 1, 0)
AND Comp_Id=161
如果你的一周没有在星期一开始然后将0更改为适当的数字。
If your week doesn't start on a Monday then change the 0s to the appropriate number.
这篇关于如何在sql中查找当前周数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文