Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .

SQL
SELECT *
FROM objectives
WHERE CompetionDate > = DATEADD(wk,DATEDIFF(wk,0, GETDATE() -1 ),0)
and Year(CompetionDate) = 2015
and Comp_Id=161
Posted

1 solution

sqlservercentral.com[^] has some useful snippets for dates.

Try something like (caveat - untested)
SQL
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
If your week doesn't start on a Monday then change the 0s to the appropriate number.
 
Share this answer
 
Comments
Torakami 7-May-15 6:54am    
Thanks , this worked for me ..
Sascha Lefèvre 7-May-15 7:37am    
+5! for exactly this answer :-)
CHill60 7-May-15 7:39am    
Thank you! To be fair, the OP was sooo close.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900