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 2005 Forums
 Transact-SQL (2005)
 Calculating Monday of the week.

Author  Topic 

soniyakapoor03
Starting Member

11 Posts

Posted - 2010-05-20 : 04:45:28
Hi,


I need to find the date of monday of the week in sql server 2005.

I am using this sql code to find it.

set DATEFIRST 1
select DATEADD(dd, 1 - DATEPART(dw, getdate()), getdate())


i am using this in UDF. it does not allow me to use set DATEFIRST 1. it is showing error.

i tried this sql also.

SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)

my week should start from Monday to sunday.

Any other option to find the monday of the week.

regards

Soniya

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-20 : 05:58:28
SELECT DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) / 7 * 7, 0) AS Monday


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -