Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Week Data

Status
Not open for further replies.

Tanya556

Technical User
Apr 5, 2002
34
US
Hello All,

Does anyone know how to return data for the current week?
 
This should work.
Code:
Select *
From myTable
Where DatePart(ww,dtmCol) = DatePart(ww,GetDate())

"Shoot Me! Shoot Me NOW!!!"
- Daffy Duck
 
In the simplest for you will have to restrict the records returned by your query to a range that includes your first and last day of the week like so 'SELECT * FROM MyTable WHERE DateField BETWEEN Date1 and Date2', where Date1 and Date2 are values you know in advance.

A combination of @@DATEFIRST and DATEADD functions should help you get the first and last date of the week in general.

Let me know if you need an example, I haven't got much time now.
 
Sure, that works too and it's even simpler but you have to decide whether the week should span months.
 
Thank you very much you guys. After I posted the thread I realized how to set it up.

DatePart("ww",[DateIn])=(DatePart("ww",Now()))

I had a brian fart...

Thank you!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top