Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-05 : 08:59:25
|
| Anees Ahmed writes "how to get the first day of the week of that date?" |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-03-05 : 10:07:13
|
| This will get you goingselect getdate()-datepart(dw,getdate())-------------------------------------------------------------- |
 |
|
|
rknewbow
Starting Member
7 Posts |
Posted - 2002-03-05 : 10:30:35
|
| Try this:if first day is SundaySELECT DATEADD(dd, -(datepart(dw, GETDATE() - 1)), GETDATE()) As FirstDayOfWeekif first day is MondaySELECT DATEADD(dd, -(datepart(dw, GETDATE() - 1)), GETDATE()) + 1 As FirstDayOfWeeki just tested Nazim's solution and it will return Saturday as the first day of the week. Add 1 to the result to get Sunday, 2 for Monday, etc. His solution looks cleaner too.Edited by - rknewbow on 03/05/2002 10:42:38 |
 |
|
|
yakoo
Constraint Violating Yak Guru
312 Posts |
Posted - 2002-03-05 : 11:31:56
|
Try thisSELECT dateadd(d, -(datepart(dw, getdate()) - 1), getdate()) "datepart(dw, getdate()) - 1" will return 0 if the day of the week is Sunday (or 1) and will return 0 days from which "dateadd" will add to getdate(). This should work with any day of the week. |
 |
|
|
|
|
|