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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 date function.

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 going

select getdate()-datepart(dw,getdate())


--------------------------------------------------------------
Go to Top of Page

rknewbow
Starting Member

7 Posts

Posted - 2002-03-05 : 10:30:35
Try this:

if first day is Sunday
SELECT DATEADD(dd, -(datepart(dw, GETDATE() - 1)), GETDATE()) As FirstDayOfWeek

if first day is Monday
SELECT DATEADD(dd, -(datepart(dw, GETDATE() - 1)), GETDATE()) + 1 As FirstDayOfWeek

i 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
Go to Top of Page

yakoo
Constraint Violating Yak Guru

312 Posts

Posted - 2002-03-05 : 11:31:56
Try this


SELECT 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.

Go to Top of Page
   

- Advertisement -