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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First Day of the Week

Status
Not open for further replies.

fmrock

Programmer
Joined
Sep 5, 2006
Messages
510
Location
US
If i have a date in a database, what is the best way to get the first day of the week (Sundays) Date?

I have the week number by doing this.

Code:
SELECT 
	DATEPART (week,QA.QADATE) "Week_Number"

 
Check out tip #5 in this FAQ. It might be what you are looking for.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
This seems to work.. clears the time and gets back to the start of the week.

Code:
	DATEPART (week,QA.QADATE) "Week_Number"
	,DATEADD(DD, 1 - DATEPART(DW, DATEADD(Day, DATEDIFF(Day, 0, QADATE), 0)), DATEADD(Day, DATEDIFF(Day, 0, QADATE), 0)) "Week_Start"
 
Thanks SQLBill I had the "look in FAQ" thought when I read the title. The only date questions should be like the thread183-1602616 as FAQ has a lot of date help.


djj
The Lord is My Shepard (Psalm 23) - I need someone to lead me!
 
I like to point people to the FAQ even if their question can be answered simply. For one thing, it lets them know there is a FAQ and second, they might find something else that they didn't know and might be able to use.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top